From jason at multiply.org Thu Jan 3 21:19:49 2008 From: jason at multiply.org (jason gessner) Date: Fri, 4 Jan 2008 00:19:49 -0500 Subject: [Chicago-talk] Question of preference In-Reply-To: <47780E3C.2040603@wrkhors.com> References: <47752643.1020706@wrkhors.com> <4e0c849b0712292214v590f5158i142d70770e8e5572@mail.gmail.com> <47780E3C.2040603@wrkhors.com> Message-ID: <4e0c849b0801032119p6b2be1ew15de03024b7bf184@mail.gmail.com> if you share your repo with a team and check in broken code you are a jerk. If you want version control bring it into a local branch or use something like svk or __INSERT FANCY NEW DISTRIBUTED VERSION CONTROL TOOL DU JOUR HERE__ to help you out, but don't pollute a shared repo with code that doesn't work. if you use VCS for yourself then you can do whatever you feel best, obviously. -jason On Dec 30, 2007 4:31 PM, Steven Lembark wrote: > > >> SVN supports this via pre-commit checks; problem > >> is that you usually want people checking in code > >> regularly to avoid loss of work. Catch: if you > >> can only check in working code then you cannot > >> make periodic checkins to make sure you don't > >> loose work. > > > > you don't want to lose code *that works* not just any random code. > > SVN != RSYNC for a developer sandbox. :) > > So if it takes you three weeks to finish some work > you wouldn't want to make any partial commits? You > would prefer not to have any option of working > on the code at remote locations, or give anyone else > working on the project with you any chance at all to > see the in-process code? You also would want to be > able to try any changes with the option of backing > them out later to a sane re-start point if an idea > didn't work, I suppose? > > I've found all of these helpful at various times. > > You might not want to put the code back into the > main production branch the first day, but the ability > to commit partially complete projects is a powerful > feature of SVN (and CVS). > > -- > Steven Lembark 85-09 90th St. > Workhorse Computing Woodhaven, NY, 11421 > lembark at wrkhors.com +1 888 359 3508 > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > From richard at rushlogistics.com Fri Jan 4 13:44:45 2008 From: richard at rushlogistics.com (Richard Reina) Date: Fri, 4 Jan 2008 13:44:45 -0800 (PST) Subject: [Chicago-talk] @ARGV while(<>) Message-ID: <878554.17858.qm@web603.biz.mail.mud.yahoo.com> I have a script like the one below that looks though a file and removes any line that contains the sequence "epsf[". Sometimes it hangs and I can't figure out why, although I suspect that it might be my while (<>) loop. Is there is something that I am doing that is careless that might hint as to why the program sometimes hangs? #!/usr/bin/perl5 -w @ARGV = $infile; my $body = ""; while(<>) { unless(/epsf\[/) { $body = $body . $_; } Your beliefs become your thoughts. Your thoughts become your words. Your words become your actions. Your actions become your habits. Your habits become your values. Your values become your destiny. -- Mahatma Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080104/a2ca8aba/attachment.html From hucke at cynico.net Fri Jan 4 13:59:07 2008 From: hucke at cynico.net (Matt Hucke) Date: Fri, 04 Jan 2008 15:59:07 -0600 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: <878554.17858.qm@web603.biz.mail.mud.yahoo.com> References: <878554.17858.qm@web603.biz.mail.mud.yahoo.com> Message-ID: <477EAC2B.7000403@cynico.net> > my $body = ""; > while(<>) { > unless(/epsf\[/) { > $body = $body . $_; > } Does it choke on extremely large files? You're doing repeated concatenation onto a string, which gets bigger each time through the loop. This might mean a lot of realloc's and copying of the string in memory. (I may be wrong, I haven't studied perl internals). Try putting the lines into an array and then join'ing them at the very end. while (<>) { push (@lines, $_) unless (/espf\[/); } my $body = join("", @lines); (I once downloaded a free program to transform a proprietary mailbox file format into standard format. It slurped the entire mailbox file into one big string, as in the sample program above, then did repeated s/foo/whatever/e on it. This worked fine for tiny files, but took forever to handle anything larger than 10MB or so. I eventually rewrote it to do line-by-line transformations). -- hucke at cynico.net http://www.graveyards.com From Andy_Bach at wiwb.uscourts.gov Fri Jan 4 14:09:49 2008 From: Andy_Bach at wiwb.uscourts.gov (Andy_Bach at wiwb.uscourts.gov) Date: Fri, 4 Jan 2008 16:09:49 -0600 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: <878554.17858.qm@web603.biz.mail.mud.yahoo.com> Message-ID: #!/usr/bin/perl5 -w @ARGV = $infile; my $body = ""; while(<>) { unless(/epsf\[/) { $body = $body . $_; } Er, $infile isn't defined so you should always hang. You're also missing the close paren for the unless while(<>) { unless(/epsf\[/) { $body = $body . $_; } # unless(/epsf\[/) } # while <> so one guesses these are typo/copy-o issue though. Normally you'd just have (call it no_epsf.pl): #!/usr/bin/perl5 -w use strict; my $body = ""; while(<>) { unless(/epsf\[/) { $body = $body . $_; } # unless(/epsf\[/) } # while <> and run it $ no_epsf.pl filename one guess you want, though $ no_epsf.pl filename > noepsf_filename so: #!/usr/bin/perl5 -w use strict; while(<>) { print unless /epsf\[/; } # while <> would work for that. s Andy Bach Systems Mangler Internet: andy_bach at wiwb.uscourts.gov VOICE: (608) 261-5738 FAX 264-5932 And the users exclaimed with a snarl and a taunt, "It's just what we asked for, but not what we want!" From merlyn at stonehenge.com Fri Jan 4 14:12:56 2008 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Fri, 04 Jan 2008 14:12:56 -0800 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: <878554.17858.qm@web603.biz.mail.mud.yahoo.com> (Richard Reina's message of "Fri, 4 Jan 2008 13:44:45 -0800 (PST)") References: <878554.17858.qm@web603.biz.mail.mud.yahoo.com> Message-ID: <861w8x5jfb.fsf@blue.stonehenge.com> >>>>> "Richard" == Richard Reina writes: Richard> #!/usr/bin/perl5 -w Richard> @ARGV = $infile; Since you haven't defined $infile here (aside: use strict would have caught this... why aren't you using it?), you're assigning @ARGV as a single undef. Richard> my $body = ""; Richard> while(<>) { Now, @ARGV contains only a single undef, which I *think* will be interpreted as the empty string, which might open up the current directory (at least, in old unix versions it would have) and read that. Probably not what you want. Richard> unless(/epsf\[/) { Richard> $body = $body . $_; Richard> } -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! From richard at rushlogistics.com Fri Jan 4 14:51:41 2008 From: richard at rushlogistics.com (Richard Reina) Date: Fri, 4 Jan 2008 14:51:41 -0800 (PST) Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: <861w8x5jfb.fsf@blue.stonehenge.com> Message-ID: <470886.96019.qm@web610.biz.mail.mud.yahoo.com> Apologies. Since the program is on a private network I am copying it into the email. Here is code with the omitted lines that come before: #!/usr/bin/perl5 -w use warnings; use strict; sub delimit { my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_; if (defined $in_file) { # file submited @ARGV = $in_file; $body = ""; while(<>) { unless(/epsf\[/) { $body = $body . $_; } # end of unless } # end of while } # end of if } # end of sub Randal what does a single undef mean? Does it mean only one file? should I do: @ARGV = qw($in_file); ? Now, @ARGV contains only a single undef, which I *think* will Thank you very much for the replies. In answering Matt's question the files are between 20 and 100 lines. Your beliefs become your thoughts. Your thoughts become your words. Your words become your actions. Your actions become your habits. Your habits become your values. Your values become your destiny. -- Mahatma Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080104/083137c8/attachment.html From me at heyjay.com Fri Jan 4 19:22:14 2008 From: me at heyjay.com (Jay Strauss) Date: Fri, 4 Jan 2008 21:22:14 -0600 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: <470886.96019.qm@web610.biz.mail.mud.yahoo.com> References: <861w8x5jfb.fsf@blue.stonehenge.com> <470886.96019.qm@web610.biz.mail.mud.yahoo.com> Message-ID: > Randal what does a single undef mean? Does it mean only one file? > > should I do: > > @ARGV = qw($in_file); Not to put words in Randal's mouth, but I believe he's refering to your original post where you have: @ARGV = $infile; And $infile has no value, i.e. undefined (based on the original post). [group] Is it just me, or does look funny to explicitly set @ARGV? I believe it is better style to open a file handle upon $infile, and do some error checking on the open. Somthing along the lines of: use strict; use Carp; my $infile = shift; my $body; open my $FILE, '<', $infile or croak "can\'t open file $infile: $!n"; while (<$FILE>) { unless(/epsf\[/) { $body = $body . $_; } } Jay From me at heyjay.com Fri Jan 4 19:26:52 2008 From: me at heyjay.com (Jay Strauss) Date: Fri, 4 Jan 2008 21:26:52 -0600 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: References: <861w8x5jfb.fsf@blue.stonehenge.com> <470886.96019.qm@web610.biz.mail.mud.yahoo.com> Message-ID: (Why is it you only notice your errors AFTER you post) should be: open my $FILE, '<', $infile or croak "can't open file $infile: $!\n"; On Jan 4, 2008 9:22 PM, Jay Strauss wrote: > > Randal what does a single undef mean? Does it mean only one file? > > > > should I do: > > > > @ARGV = qw($in_file); > > Not to put words in Randal's mouth, but I believe he's refering to > your original post where you have: > > @ARGV = $infile; > > And $infile has no value, i.e. undefined (based on the original post). > > [group] Is it just me, or does look funny to explicitly set @ARGV? > > I believe it is better style to open a file handle upon $infile, and > do some error checking on the open. > > Somthing along the lines of: > > use strict; > use Carp; > > my $infile = shift; > my $body; > > open my $FILE, '<', $infile or croak "can\'t open file $infile: $!n"; > while (<$FILE>) { > unless(/epsf\[/) { > $body = $body . $_; > } > } > > > Jay > From richard at rushlogistics.com Sat Jan 5 06:49:12 2008 From: richard at rushlogistics.com (Richard Reina) Date: Sat, 5 Jan 2008 06:49:12 -0800 (PST) Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: Message-ID: <923064.36117.qm@web609.biz.mail.mud.yahoo.com> [group] Is it just me, or does look funny to explicitly set @ARGV? Jay, Not to say that your assertion is without merit -- I know less perl than anyone on the list and probably anyone on any list for that matter. However, in explicitly setting @ARGV I was following the example on page 72 of Learning Perl 4th addition, which has always steered me right in the past. Thanks for all the responses. For now I am going to try Matt's suggestion of pushing the $_ into and array and joining them after the while loop, but I continue to be open to any and all suggestions. Thanks again. Have a great Saturday! Your beliefs become your thoughts. Your thoughts become your words. Your words become your actions. Your actions become your habits. Your habits become your values. Your values become your destiny. -- Mahatma Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080105/6971de23/attachment-0001.html From me at heyjay.com Sat Jan 5 07:11:06 2008 From: me at heyjay.com (Jay Strauss) Date: Sat, 5 Jan 2008 09:11:06 -0600 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: <923064.36117.qm@web609.biz.mail.mud.yahoo.com> References: <923064.36117.qm@web609.biz.mail.mud.yahoo.com> Message-ID: On Jan 5, 2008 8:49 AM, Richard Reina wrote: > > [group] Is it just me, or does look funny to explicitly set @ARGV? > Jay, Not to say that your assertion is without merit -- I know less perl > than anyone on the list and probably anyone on any list for that matter. > However, in explicitly setting @ARGV I was following the example on page 72 > of Learning Perl 4th addition, which has always steered me right in the > past. Then it's probably just me. :) I've never claimed to be any expert. Jay From merlyn at stonehenge.com Sat Jan 5 08:42:54 2008 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Sat, 05 Jan 2008 08:42:54 -0800 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: (Jay Strauss's message of "Fri, 4 Jan 2008 21:22:14 -0600") References: <861w8x5jfb.fsf@blue.stonehenge.com> <470886.96019.qm@web610.biz.mail.mud.yahoo.com> Message-ID: <86fxxc441d.fsf@blue.stonehenge.com> >>>>> "Jay" == Jay Strauss writes: Jay> [group] Is it just me, or does look funny to explicitly set @ARGV? I do it all the time. It's a convenient way to set up a 'while (<>)' loop which in turn is a convenient way to read a series of files. For example, look through all text files in the current directory: @ARGV = grep -T, glob '*'; while (<>) { ... } Look through all the '.htaccess' files in my webserver area: use File::Finder; @ARGV = File::Finder->type('f')->name('.htaccess')->in($HTDOC); ... etc etc. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! From andy at petdance.com Sat Jan 5 08:45:28 2008 From: andy at petdance.com (Andy Lester) Date: Sat, 5 Jan 2008 10:45:28 -0600 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: <86fxxc441d.fsf@blue.stonehenge.com> References: <861w8x5jfb.fsf@blue.stonehenge.com> <470886.96019.qm@web610.biz.mail.mud.yahoo.com> <86fxxc441d.fsf@blue.stonehenge.com> Message-ID: <3EEFAF6A-5345-408A-ABC7-F37907BE66FB@petdance.com> On Jan 5, 2008, at 10:42 AM, Randal L. Schwartz wrote: > Jay> [group] Is it just me, or does look funny to explicitly set > @ARGV? > > I do it all the time. It's a convenient way to set up a 'while > (<>)' loop > which in turn is a convenient way to read a series of files. I also do it in ack, where I do the globbing for the Windows guys whose shell doesn't glob for them. -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance From richard at rushlogistics.com Sat Jan 5 13:36:48 2008 From: richard at rushlogistics.com (Richard Reina) Date: Sat, 5 Jan 2008 13:36:48 -0800 (PST) Subject: [Chicago-talk] isolating the values to right and left of the decimal Message-ID: <136372.59970.qm@web607.biz.mail.mud.yahoo.com> After over an hour of googling and searching in my Lama, Camel and Ram books I still am unable to find a way to convert 13.32 to: thirteen hours and nineteen minutes my $time_sring = 13.32; my $hrs = sprintf "%0d", $time_string; # works. I get 13 but I can't figure out how to get .32 so that I can multiply it time 60 and then round it so that I can print out: thirteen hours and nineteen minutes Any help would be greatly appreciated. Thanks, Richard Your beliefs become your thoughts. Your thoughts become your words. Your words become your actions. Your actions become your habits. Your habits become your values. Your values become your destiny. -- Mahatma Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080105/890550cf/attachment.html From lembark at wrkhors.com Sat Jan 5 14:02:05 2008 From: lembark at wrkhors.com (Steven Lembark) Date: Sat, 05 Jan 2008 17:02:05 -0500 Subject: [Chicago-talk] isolating the values to right and left of the decimal In-Reply-To: <136372.59970.qm@web607.biz.mail.mud.yahoo.com> References: <136372.59970.qm@web607.biz.mail.mud.yahoo.com> Message-ID: <477FFE5D.4050407@wrkhors.com> Richard Reina wrote: > After over an hour of googling and searching in my Lama, Camel and Ram > books I still am unable to find a way to convert > > 13.32 to: thirteen hours and nineteen minutes > > my $time_sring = 13.32; > > my $hrs = sprintf "%0d", $time_string; # works. I get 13 > > but I can't figure out how to get .32 so that I can multiply it time 60 > and then round it so that I can print out: > > thirteen hours and nineteen minutes my $time = 13.32; my $hours = int $decimal_time; my $min = ( $decimal_time - $hours ) * 60; my $timestr = sprintf '%02d:%02d', $hrs, $min; -- Steven Lembark 85-09 90th St. Workhorse Computing Woodhaven, NY, 11421 lembark at wrkhors.com +1 888 359 3508 From dave at obtiva.com Sat Jan 5 14:15:45 2008 From: dave at obtiva.com (Dave Hoover) Date: Sat, 5 Jan 2008 16:15:45 -0600 Subject: [Chicago-talk] isolating the values to right and left of the decimal In-Reply-To: <136372.59970.qm@web607.biz.mail.mud.yahoo.com> References: <136372.59970.qm@web607.biz.mail.mud.yahoo.com> Message-ID: <11c8704e0801051415h443a66dy5baafc7d5c2bcfaf@mail.gmail.com> Richard Reina wrote: > my $time_sring = 13.32; > > my $hrs = sprintf "%0d", $time_string; # works. I get 13 > > but I can't figure out how to get .32 so that I can multiply it time 60 and > then round it so that I can print out: > > thirteen hours and nineteen minutes > > Any help would be greatly appreciated. I'm sure there's a better way to do it, but here's the first to pop into my mind. $decimal = 12.34; @sides = $decimal =~ /(\d+)/g; print $sides[1], "\n"; Best, Dave Hoover //obtiva - agilty applied. software delivered. From richard at rushlogistics.com Sat Jan 5 14:35:28 2008 From: richard at rushlogistics.com (Richard Reina) Date: Sat, 5 Jan 2008 14:35:28 -0800 (PST) Subject: [Chicago-talk] isolating the values to right and left of the decimal In-Reply-To: <477FFE5D.4050407@wrkhors.com> Message-ID: <634136.70456.qm@web613.biz.mail.mud.yahoo.com> Steve, thank you very much. I did not know about the int operator. Works like a charm. Thank you very much. Have a great night! Steven Lembark wrote: Richard Reina wrote: > After over an hour of googling and searching in my Lama, Camel and Ram > books I still am unable to find a way to convert > > 13.32 to: thirteen hours and nineteen minutes > > my $time_sring = 13.32; > > my $hrs = sprintf "%0d", $time_string; # works. I get 13 > > but I can't figure out how to get .32 so that I can multiply it time 60 > and then round it so that I can print out: > > thirteen hours and nineteen minutes my $time = 13.32; my $hours = int $decimal_time; my $min = ( $decimal_time - $hours ) * 60; my $timestr = sprintf '%02d:%02d', $hrs, $min; -- Steven Lembark 85-09 90th St. Workhorse Computing Woodhaven, NY, 11421 lembark at wrkhors.com +1 888 359 3508 _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk Your beliefs become your thoughts. Your thoughts become your words. Your words become your actions. Your actions become your habits. Your habits become your values. Your values become your destiny. -- Mahatma Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080105/a0e72c75/attachment.html From autarch at urth.org Mon Jan 7 09:01:37 2008 From: autarch at urth.org (Dave Rolsky) Date: Mon, 7 Jan 2008 11:01:37 -0600 (CST) Subject: [Chicago-talk] Frozen Perl 2008 early bird deadline is approaching. Message-ID: The early bird deadline for Frozen Perl 2008 is fast approaching. After midnight Central on Saturday, January 12th, the rate for non-students will double from $20 to $40. Frozen Perl 2008 is a one-day Perl workshop happening on Saturday, February 16th, with a great schedule of speakers. The theme is "Perl in Practice", and there are a lot of great talks. We have two tracks of talks. For folks new to Perl, there is a strong slate of talks for beginners, including introductions to OOP, testing, and more. For more experienced Perlers, there are talks on Moose, Catalyst, and all sorts of interesting Perl wizardry. Registration includes breakfast and lunch, and possibly a t-shirt, all for the ridiculously cheap price of $20. If you're coming from out of town, there is a group rate at the nearby Days Inn. There will also be an all-day hackathon on Sunday, February 17th for the true geeks. For more information, check out the website at http://www.frozen-perl.org/. You can sign up online, so don't delay. We hope to see you there. Dave Rolsky Frozen Perl 2008 Organizer From richard at rushlogistics.com Tue Jan 8 06:55:49 2008 From: richard at rushlogistics.com (Richard Reina) Date: Tue, 8 Jan 2008 06:55:49 -0800 (PST) Subject: [Chicago-talk] A CLUE @ARGV while(<>) In-Reply-To: <3EEFAF6A-5345-408A-ABC7-F37907BE66FB@petdance.com> Message-ID: <264369.41791.qm@web612.biz.mail.mud.yahoo.com> Progress, maybe. I believe this script is hanging at the line push(@lines, $_) unless (/espf\[/); I believe this because in cases when it hangs, if I do a Cntl-C I get: Not a subroutine reference at ./file_delimiter.pl line 24, <> line3. This is turning out to be a disruptive problem here. Any help would be greatly appreciated. #!/usr/bin/perl5 -w use warnings; use strict; sub delimit { my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_; if (defined $in_file) { # file submited @ARGV = $in_file; $body = ""; while(<>) { push(@lines, $_) unless (/espf\[/); # hangs here sometimes } # end of while } # end of if } # end of sub -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080108/3b531d01/attachment.html From tzz at lifelogs.com Tue Jan 8 15:57:38 2008 From: tzz at lifelogs.com (Ted Zlatanov) Date: Tue, 08 Jan 2008 17:57:38 -0600 Subject: [Chicago-talk] A CLUE @ARGV while(<>) In-Reply-To: <264369.41791.qm@web612.biz.mail.mud.yahoo.com> (Richard Reina's message of "Tue, 8 Jan 2008 06:55:49 -0800 (PST)") References: <264369.41791.qm@web612.biz.mail.mud.yahoo.com> Message-ID: <86ir23kgzx.fsf@lifelogs.com> On Tue, 8 Jan 2008 06:55:49 -0800 (PST) Richard Reina wrote: RR> Progress, maybe. I believe this script is hanging at the line push(@lines, $_) unless (/espf\[/); RR> I believe this because in cases when it hangs, if I do a Cntl-C I get: RR> Not a subroutine reference at ./file_delimiter.pl line 24, <> line3. RR> This is turning out to be a disruptive problem here. Any help would be greatly appreciated. RR> #!/usr/bin/perl5 -w RR> use warnings; RR> use strict; RR> sub delimit { RR> my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_; RR> if (defined $in_file) { # file submited RR> @ARGV = $in_file; RR> $body = ""; RR> while(<>) { RR> push(@lines, $_) unless (/espf\[/); # hangs here sometimes RR> } # end of while RR> } # end of if RR> } # end of sub It's unlikely this is your script, since line 24 is at the end and @lines is not declared, which wouldn't work under `use strict'. Can you please post your actual code that hangs? Also try some debugging output (or the Perl debugger with a watch). FWIW, I'd write delimit() like this (untested): sub delimit { my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_; return unless defined $in_file; open IN, '<', $in_file or warn "Could not open $in_file: $!"; my @lines; while (my $line = ) { next if $line =~ m/espf\[/; push(@lines, $line); } } Note how the open() will tell you if it couldn't open the input file, which could be one of your problems. Anyhow, don't post broken code, no one can help you fix it. Ted From richard at rushlogistics.com Tue Jan 8 16:03:29 2008 From: richard at rushlogistics.com (Richard Reina) Date: Tue, 8 Jan 2008 16:03:29 -0800 (PST) Subject: [Chicago-talk] A CLUE @ARGV while(<>) In-Reply-To: <86ir23kgzx.fsf@lifelogs.com> Message-ID: <589062.27220.qm@web602.biz.mail.mud.yahoo.com> Ted, Thank you for your reply. I will work on adding some debugging. Thanks again, Richard Ted Zlatanov <@lifelogs.com> wrote: On Tue, 8 Jan 2008 06:55:49 -0800 (PST) Richard Reina wrote: RR> Progress, maybe. I believe this script is hanging at the line push(@lines, $_) unless (/espf\[/); RR> I believe this because in cases when it hangs, if I do a Cntl-C I get: RR> Not a subroutine reference at ./file_delimiter.pl line 24, <> line3. RR> This is turning out to be a disruptive problem here. Any help would be greatly appreciated. RR> #!/usr/bin/perl5 -w RR> use warnings; RR> use strict; RR> sub delimit { RR> my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_; RR> if (defined $in_file) { # file submited RR> @ARGV = $in_file; RR> $body = ""; RR> while(<>) { RR> push(@lines, $_) unless (/espf\[/); # hangs here sometimes RR> } # end of while RR> } # end of if RR> } # end of sub It's unlikely this is your script, since line 24 is at the end and @lines is not declared, which wouldn't work under `use strict'. Can you please post your actual code that hangs? Also try some debugging output (or the Perl debugger with a watch). FWIW, I'd write delimit() like this (untested): sub delimit { my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_; return unless defined $in_file; open IN, '<', $in_file or warn "Could not open $in_file: $!"; my @lines; while (my $line = ) { next if $line =~ m/espf\[/; push(@lines, $line); } } Note how the open() will tell you if it couldn't open the input file, which could be one of your problems. Anyhow, don't post broken code, no one can help you fix it. Ted _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk Your beliefs become your thoughts. Your thoughts become your words. Your words become your actions. Your actions become your habits. Your habits become your values. Your values become your destiny. -- Mahatma Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080108/03db25c6/attachment.html From richard at rushlogistics.com Wed Jan 9 11:18:25 2008 From: richard at rushlogistics.com (Richard Reina) Date: Wed, 9 Jan 2008 11:18:25 -0800 (PST) Subject: [Chicago-talk] A CLUE @ARGV while(<>) In-Reply-To: <86ir23kgzx.fsf@lifelogs.com> Message-ID: <442144.81349.qm@web611.biz.mail.mud.yahoo.com> Ted, Thank you very much for the suggested rewrite for the subroutine. So far it has not hung (fingers crossed). However, the lines with espf[ in them are not being removed with: next if $line =~ m/espf\[/; For example, if the $in_file contains the line: ^epsf[cs.45]{../rush_graphics/truck_slogan5.eps} it does not get removed. Did I do something wrong? Ted Zlatanov wrote:sub delimit { my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_; return unless defined $in_file; open IN, '<', $in_file or warn "Could not open $in_file: $!"; my @lines; while (my $line = ) { next if $line =~ m/espf\[/; push(@lines, $line); } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080109/17a7df76/attachment.html From tzz at lifelogs.com Wed Jan 9 11:28:20 2008 From: tzz at lifelogs.com (Ted Zlatanov) Date: Wed, 09 Jan 2008 13:28:20 -0600 Subject: [Chicago-talk] A CLUE @ARGV while(<>) In-Reply-To: <442144.81349.qm@web611.biz.mail.mud.yahoo.com> (Richard Reina's message of "Wed, 9 Jan 2008 11:18:25 -0800 (PST)") References: <442144.81349.qm@web611.biz.mail.mud.yahoo.com> Message-ID: <86zlvehk8b.fsf@lifelogs.com> On Wed, 9 Jan 2008 11:18:25 -0800 (PST) Richard Reina wrote: RR> Thank you very much for the suggested rewrite for the subroutine. RR> So far it has not hung (fingers crossed). However, the lines with RR> espf[ in them are not being removed with: RR> next if $line =~ m/espf\[/; RR> For example, if the $in_file contains the line: RR> ^epsf[cs.45]{../rush_graphics/truck_slogan5.eps} RR> it does not get removed. Did I do something wrong? I think so, the regular expression uses `espf' and your data has `epsf' so they won't match. Ted From richard at rushlogistics.com Wed Jan 9 11:34:16 2008 From: richard at rushlogistics.com (Richard Reina) Date: Wed, 9 Jan 2008 11:34:16 -0800 (PST) Subject: [Chicago-talk] A CLUE @ARGV while(<>) In-Reply-To: <86zlvehk8b.fsf@lifelogs.com> Message-ID: <604181.48701.qm@web615.biz.mail.mud.yahoo.com> Sorry for the careless oversight. Thanks again. Ted Zlatanov wrote: On Wed, 9 Jan 2008 11:18:25 -0800 (PST) Richard Reina wrote: RR> Thank you very much for the suggested rewrite for the subroutine. RR> So far it has not hung (fingers crossed). However, the lines with RR> espf[ in them are not being removed with: RR> next if $line =~ m/espf\[/; RR> For example, if the $in_file contains the line: RR> ^epsf[cs.45]{../rush_graphics/truck_slogan5.eps} RR> it does not get removed. Did I do something wrong? I think so, the regular expression uses `espf' and your data has `epsf' so they won't match. Ted _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk Your beliefs become your thoughts. Your thoughts become your words. Your words become your actions. Your actions become your habits. Your habits become your values. Your values become your destiny. -- Mahatma Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080109/2c98ce2e/attachment.html From tigerpeng2001 at yahoo.com Wed Jan 9 13:01:43 2008 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Wed, 9 Jan 2008 13:01:43 -0800 (PST) Subject: [Chicago-talk] isolating the values to right and left of the decimal Message-ID: <502712.80411.qm@web58704.mail.re1.yahoo.com> Here is my solution for fun: perl -e '$t=13.32; $t =~ s/(\d+)(\.\d+)/$1.":". (int $2*60 + .5<10?"0":"").int $2*60 + .5/e; print "$t\n"' ----- Original Message ---- From: Richard Reina To: chicago-talk at pm.org Sent: Saturday, January 5, 2008 3:36:48 PM Subject: [Chicago-talk] isolating the values to right and left of the decimal After over an hour of googling and searching in my Lama, Camel and Ram books I still am unable to find a way to convert 13.32 to: thirteen hours and nineteen minutes my $time_sring = 13.32; my $hrs = sprintf "%0d", $time_string; # works. I get 13 but I can't figure out how to get .32 so that I can multiply it time 60 and then round it so that I can print out: thirteen hours and nineteen minutes Any help would be greatly appreciated. Thanks, Richard Your beliefs become your thoughts. Your thoughts become your words. Your words become your actions. Your actions become your habits. Your habits become your values. Your values become your destiny. -- Mahatma Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080109/fe2534bc/attachment.html From tzz at lifelogs.com Wed Jan 9 13:52:59 2008 From: tzz at lifelogs.com (Ted Zlatanov) Date: Wed, 09 Jan 2008 15:52:59 -0600 Subject: [Chicago-talk] isolating the values to right and left of the decimal In-Reply-To: <502712.80411.qm@web58704.mail.re1.yahoo.com> (tiger peng's message of "Wed, 9 Jan 2008 13:01:43 -0800 (PST)") References: <502712.80411.qm@web58704.mail.re1.yahoo.com> Message-ID: <86bq7uhdj8.fsf@lifelogs.com> On Wed, 9 Jan 2008 13:01:43 -0800 (PST) tiger peng wrote: tp> Here is my solution for fun: tp> perl -e '$t=13.32; $t =~ s/(\d+)(\.\d+)/$1.":". (int $2*60 + .5<10?"0":"").int $2*60 + .5/e; print "$t\n"' I think this is a little cleaner as a one-liner and will work with $t = .32 for example: perl -e'$t = 13.32; printf "%d:%d\n", $t, ($t*60)%60;' Ted From tigerpeng2001 at yahoo.com Wed Jan 9 13:59:23 2008 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Wed, 9 Jan 2008 13:59:23 -0800 (PST) Subject: [Chicago-talk] isolating the values to right and left of the decimal Message-ID: <913250.26351.qm@web58701.mail.re1.yahoo.com> > tp> Here is my solution for fun: >tp> perl -e '$t=13.32; $t =~ s/(\d+)(\.\d+)/$1.":". (int $2*60 + .5<10?"0":"").int $2*60 + .5/e; print "$t\n"' >I think this is a little cleaner as a one-liner and will work with >$t = .32 for example: > perl -e'$t = 13.32; printf "%d:%d\n", $t, ($t*60)%60;' There is a small bug: -> perl -e'$t = 13.02; printf "%d:%d\n", $t, ($t*60)%60;' 13:1 Ted _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080109/4a453da4/attachment.html From tzz at lifelogs.com Wed Jan 9 14:13:05 2008 From: tzz at lifelogs.com (Ted Zlatanov) Date: Wed, 09 Jan 2008 16:13:05 -0600 Subject: [Chicago-talk] isolating the values to right and left of the decimal In-Reply-To: <913250.26351.qm@web58701.mail.re1.yahoo.com> (tiger peng's message of "Wed, 9 Jan 2008 13:59:23 -0800 (PST)") References: <913250.26351.qm@web58701.mail.re1.yahoo.com> Message-ID: <86zlvefy1a.fsf@lifelogs.com> On Wed, 9 Jan 2008 13:59:23 -0800 (PST) tiger peng wrote: tp> Here is my solution for fun: tp> perl -e '$t=13.32; $t =~ s/(\d+)(\.\d+)/$1.":". (int $2*60 + tp> .5<10?"0":"").int $2*60 + .5/e; print "$t\n"' >> I think this is a little cleaner as a one-liner and will work with >> $t = .32 for example: >> perl -e'$t = 13.32; printf "%d:%d\n", $t, ($t*60)%60;' tp> There is a small bug: -> perl -e'$t = 13.02; printf "%d:%d\n", $t, ($t*60)%60;' tp> 13:1 Yeah, the format could be better for human consumption: perl -e'$t = 13.02; printf "%02d:%02d\n", $t, ($t*60)%60;' Thanks Ted From dave at obtiva.com Thu Jan 10 05:19:34 2008 From: dave at obtiva.com (Dave Hoover) Date: Thu, 10 Jan 2008 07:19:34 -0600 Subject: [Chicago-talk] The JavaScript Renaissance Part I: The Core Language In-Reply-To: <11c8704e0712171402l36e95bb8j9ac5750074080f32@mail.gmail.com> References: <11c8704e0712171402l36e95bb8j9ac5750074080f32@mail.gmail.com> Message-ID: <11c8704e0801100519j155dcdc0ra3e7774d877b5510@mail.gmail.com> Thanks to everyone who turned out on Tuesday in Wheaton for a great night of JavaScript learning. There were many great questions. Thanks to Fred for the time and energy he put into preparing such an in-depth tutorial. Part 2 of Fred's talk will likely be coming in February. Fred has posted his presentation materials to his blog. http://sustainablecode.com/blog/2008/01/advanced-javascript-not-for-faint-of.html Best, Dave Hoover //obtiva: Agility applied. Software delivered. On Dec 17, 2007 4:02 PM, Dave Hoover wrote: > We're going to shift gears a bit for our January meeting in Wheaton > and focus on JavaScript. Fred Polgardy has stepped forward and > volunteered to give a series of talks in 2008 on JavaScript and the > Renaissance it has enjoyed over the last couple years. > > When: Tuesday, Jan 8, 2008, 7-9 PM > Where: Wheaton, IIT - Rice Campus > Who: Frederick Polgardy > What: The JavaScript Renaissance Part I: The Core Language > > What comes to mind when think of JavaScript? Broken web sites, browser > incompatibilities, and brittle spaghetti code? It doesn't have to be > this way anymore! In this presentation, we'll take a focused look at > some of the most powerful and under-appreciated features of the core > JavaScript language -- prototype-based inheritance, lexical closures, > and metaprogramming. We'll look briefly at what these features > actually provide from a language standpoint, and then spend most of > our time rolling up our sleeves and digging into real world code. In > the process, we'll get acquainted with the Prototype library, and see > how it extends the core JavaScript language in fascinating and clever > ways. We'll finish up with a brief look at what's coming in JavaScript > 2.0. > > More information and directions can be found at > http://chicago.pm.org/meetings/ > > Let me know if you have ideas for other talks in 2008. > > Best, > > Dave Hoover From tom at yarrish.com Fri Jan 11 08:06:48 2008 From: tom at yarrish.com (Tom Yarrish) Date: Fri, 11 Jan 2008 10:06:48 -0600 (CST) Subject: [Chicago-talk] OT - Mac Leopard App Message-ID: <32762289.97751200067608934.JavaMail.root@excelsior.yarrish.com> Hey all, I know this is off topic, but someone told me about this at the Perl birthday party last month (so I'm assuming he reads this list). Someone at dinner had told me about a Mac application that could scan all my Tiger apps on my computer and then tell me which ones are Leopard compatible. I'm getting ready to upgrade my other machines, but I want to make sure all my apps are ready. Thanks, Tom -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHXgrFZWzkfeDiTw4RAozoAKCMRphwyM/wT9AbB+PMX68FUN8nEgCfX7Nu n7B9YcXwARSuuLdfbmznm/k= =5/ey -----END PGP SIGNATURE----- From tigerpeng2001 at yahoo.com Fri Jan 11 19:55:57 2008 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Fri, 11 Jan 2008 19:55:57 -0800 (PST) Subject: [Chicago-talk] A CLUE @ARGV while(<>) Message-ID: <98650.93134.qm@web58711.mail.re1.yahoo.com> Is the script not for UNIX/Linux? I investigated the failure of some scripts moved from Linux to Windows (Cygwin). There were some subtle differences between these two environments on opening/closing file handle. ----- Original Message ---- From: Richard Reina To: Chicago.pm chatter Sent: Wednesday, January 9, 2008 1:18:25 PM Subject: Re: [Chicago-talk] A CLUE @ARGV while(<>) Ted, Thank you very much for the suggested rewrite for the subroutine. So far it has not hung (fingers crossed). However, the lines with espf[ in them are not being removed with: next if $line =~ m/espf\[/; For example, if the $in_file contains the line: ^epsf[cs.45]{../rush_graphics/truck_slogan5.eps}it does not get removed. Did I do something wrong? Ted Zlatanov wrote: sub delimit { my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_; return unless defined $in_file; open IN, '<', $in_file or warn "Could not open $in_file: $!"; my @lines; while (my $line = ) { next if $line =~ m/espf\[/; push(@lines, $line); } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080111/91074147/attachment.html From lembark at wrkhors.com Sun Jan 13 16:02:55 2008 From: lembark at wrkhors.com (Steven Lembark) Date: Sun, 13 Jan 2008 19:02:55 -0500 Subject: [Chicago-talk] Question of preference In-Reply-To: <4e0c849b0801032119p6b2be1ew15de03024b7bf184@mail.gmail.com> References: <47752643.1020706@wrkhors.com> <4e0c849b0712292214v590f5158i142d70770e8e5572@mail.gmail.com> <47780E3C.2040603@wrkhors.com> <4e0c849b0801032119p6b2be1ew15de03024b7bf184@mail.gmail.com> Message-ID: <478AA6AF.4060304@wrkhors.com> jason gessner wrote: > if you share your repo with a team and check in broken code you are a > jerk. If you want version control bring it into a local branch or use > something like svk or __INSERT FANCY NEW DISTRIBUTED VERSION CONTROL > TOOL DU JOUR HERE__ to help you out, but don't pollute a shared repo > with code that doesn't work. > > if you use VCS for yourself then you can do whatever you feel best, obviously. You may be assuming that there was only one directory (trunk) in an SVN reposotiry or only untagged code in the CVS repository. In most situations it can be helpful to have mutiple directories (in svn) or tags (in CVS). What works well in most situations with SVN is to have a 'developers' branch where people can work on their own code (e.g., ./devel/). After the code is tested it can be merged back to the trunk or whatever bugfix it was sourced from. This allows developers to checkpoint code by checking it into the repository without affecting the working branches used for reference or QA. In CVS this is done by tagging the current code as being usable when the tests are complete. In that case anyone who wants a stable release simply checks out the stable tag. -- Steven Lembark 85-09 90th St. Workhorse Computing Woodhaven, NY, 11421 lembark at wrkhors.com +1 888 359 3508 From lembark at wrkhors.com Sun Jan 13 16:12:15 2008 From: lembark at wrkhors.com (Steven Lembark) Date: Sun, 13 Jan 2008 19:12:15 -0500 Subject: [Chicago-talk] @ARGV while(<>) In-Reply-To: <477EAC2B.7000403@cynico.net> References: <878554.17858.qm@web603.biz.mail.mud.yahoo.com> <477EAC2B.7000403@cynico.net> Message-ID: <478AA8DF.402@wrkhors.com> > You're doing repeated concatenation onto a string, which gets bigger each time through the loop. > This might mean a lot of realloc's and copying of the string in memory. (I may be wrong, I haven't > studied perl internals). > > Try putting the lines into an array and then join'ing them at the very end. > > while (<>) > { > push (@lines, $_) unless (/espf\[/); > } > my $body = join("", @lines); Perl strings are C strings with a start pointer and size_t length. Eating into the start simply updates the starting pointer; cutting off the end reduces the length. So, yes, $a .= $b will become expensive. Catch: It is equally expenseive in the array case since you end up having to re-allocate the array when it grows. Not quite as much coping, but likley the number of lines in the file. Ways to get around this include: - Presize the array and grow it in chunks as it progresses. This will reduce the number of copy operations to manageable level (e.g., 1_000 line chunks): my @bufferz = (); $#bufferz = 1_000; my $i = 0; while( ) { # clean up $_; $bufferz[ $i ] = $_; if( ++$i > $#bufferz ) { $#bufferz += 1_000; $size = $#bufferz; } } - Write the stuff out as it is processed and read it back with a single array/slurp read: open my $tmpfile, '+>', '/var/tmp/$$.tmp' or die ...; while( ) { ... print $tmpfile $_; } seek $tmpfile, 0, 0; my @linz = <$tmpfile> ... # or my $linz = do { local $/; <$tmpfile> } -- Steven Lembark 85-09 90th St. Workhorse Computing Woodhaven, NY, 11421 lembark at wrkhors.com +1 888 359 3508 From hucke at cynico.net Wed Jan 16 10:50:40 2008 From: hucke at cynico.net (Matt Hucke) Date: Wed, 16 Jan 2008 12:50:40 -0600 Subject: [Chicago-talk] calling functions in a package by its name Message-ID: <478E5200.4060406@cynico.net> Hi, I have a project in which I make much use of package names that aren't known at compile-time, but are instead read from a config file. I'd like to be able to load modules, create objects, and call arbitrary functions in unknown packages without an object reference. Right now, I can do it by making more use of 'eval' than I'm comfortable with. Example package: package MysteryClass; use strict; our %secretStuff = ( # caller doesn't know this variable name text => 'this is config info about package ' . __PACKAGE__ ); sub getConfig # public API, implemented by lots of similar classes { return \%secretStuff; } sub new { my ($class, %args) = @_; my $self = { name => $args{name} || "John Doe", }; bless ($self, $class); print "I am a new '$class'\n"; return $self; } sub doSomethingUseful { my ($self) = @_; print "Hello World from " . ref($self) . "!\n"; } 1; What I'd like to do is call functions in this package, without explicitly using its name, or creating an object. Presently, I use lots of "eval"'s, and it works: # test.pm use strict; use Data::Dumper; exit(main()); sub main { my $classname = "MysteryClass"; # in real life, read it from a config file. # Load a module identified only at runtime my $prog = "use $classname;"; eval $prog; die("eval '$prog' failed with " . $@ ) if ($@); # call a static function from this module, without an object ref my $conf; $prog = '$conf = ' . $classname . '::getConfig();'; eval $prog; die("eval '$prog' failed with " . $@ ) if ($@); print "config is: ". Dumper($conf); # create an object my $fred; my $name = "Fred"; $prog = '$fred=new ' . $classname . '(name => $name)'; eval $prog; die("eval '$prog' failed with " . $@ ) if ($@); print "object is: ". Dumper($fred); } I have been wondering if there's a better way to do it. PerlCritic tells me that stringy eval is bad; a bit of googling tells me that it's considered harmful because it causes the interpreter to begin another parsing phase. Can anyone offer ways to call a function (known at compile-time) in a class known only at run-time, with neither an object reference or "eval"? Ideally, I'd also like to be able to do something like "isa" or "can" using just the class name (after use'ing it) - that way I can have some sanity checking of whatever class name the user put in the config file, rather than creating a wholly inappropriate object type and only finding out later that it won't fit. The project is a web framework that allows for object types to be specified in the config file: session-manager = FileSession # (or DatabaseSession or NullSession) template-adapter = TemplateToolkitAdapter # (or TextTemplateAdapter or others) user-object-class = LocalStuff::MySiteUser # (classes might be customer-written rather than # part of the framework) (None of this is really critical... right now, I have a solution - lots of eval's - I'm just hoping for something a bit more efficient). thanks -- hucke at cynico.net http://www.graveyards.com From jon at jrock.us Wed Jan 16 12:07:29 2008 From: jon at jrock.us (Jonathan Rockway) Date: Wed, 16 Jan 2008 14:07:29 -0600 Subject: [Chicago-talk] calling functions in a package by its name In-Reply-To: <478E5200.4060406@cynico.net> References: <478E5200.4060406@cynico.net> Message-ID: <1200514049.10183.72.camel@bar.jrock.us> On Wed, 2008-01-16 at 12:50 -0600, Matt Hucke wrote: > Hi, Hi! > > I have a project in which I make much use of package names that aren't known at compile-time, but > are instead read from a config file. I'd like to be able to load modules, create objects, and call > arbitrary functions in unknown packages without an object reference. > > Right now, I can do it by making more use of 'eval' than I'm comfortable with. > > Example package: > > package MysteryClass; > use strict; > > our %secretStuff = ( # caller doesn't know this variable name > text => 'this is config info about package ' . __PACKAGE__ > ); > > sub getConfig # public API, implemented by lots of similar classes > { > return \%secretStuff; > } First off %secretStuff isn't secret, it's a package variable. That means it's global and anyone can get at it with % MysteryClass::secretStuff. "my" can be package-scoped; use that instead. (Is using our necessarily bad? No. But my might be what you were intending.) > > sub main > { > my $classname = "MysteryClass"; # in real life, read it from a config file. > > # Load a module identified only at runtime > my $prog = "use $classname;"; > eval $prog; die("eval '$prog' failed with " . $@ ) if ($@); You do have to use string eval to load the class. require is better than use here, though. (Do you want $class->import to be called? Not for classes, usually.) > > # call a static function from this module, without an object ref > my $conf; > $prog = '$conf = ' . $classname . '::getConfig();'; > eval $prog; die("eval '$prog' failed with " . $@ ) if ($@); > print "config is: ". Dumper($conf); Better to rewrite getConfig as: sub getConfig { my $class = shift; return $class_data } Then you can say: my $config = $class->getConfig; > > # create an object > my $fred; > my $name = "Fred"; > $prog = '$fred=new ' . $classname . '(name => $name)'; > eval $prog; die("eval '$prog' failed with " . $@ ) if ($@); > print "object is: ". Dumper($fred); Indirect method call syntax is a terrible habit to get into. Never use it. Let me show you some examples. When you write: my $foo = new Foo(args => 'go here'); it's hard to see what's going on. Let's try writing it with a direct call: my $foo = Foo->new(args => 'go here'); Clearer. Maybe we can do this? my $class = 'Foo'; my $foo = $class->new(args => 'go here'); Yes, of course we can :) And now you don't need eval. This applies to methods also: my $class = 'Foo'; my $constructor = 'new'; my $foo = $class->$constructor(@args); > } > > > I have been wondering if there's a better way to do it. PerlCritic tells me that stringy eval is > bad; a bit of googling tells me that it's considered harmful because it causes the interpreter to > begin another parsing phase. No, it's harmful because of: my $class = "Foo; `rm -rf *`" eval "require $class"; Or similar. > > Can anyone offer ways to call a function (known at compile-time) in a class known only at run-time, > with neither an object reference or "eval"? > > Ideally, I'd also like to be able to do something like "isa" or "can" using just the class name > (after use'ing it) - that way I can have some sanity checking of whatever class name the user put in > the config file, rather than creating a wholly inappropriate object type and only finding out later > that it won't fit. How about: my $class = 'Foo'; eval "require $class"; $class->can('new')->(); # Foo->new() One more thing, you wrote: exit(main()); sub main { ... print "object is: ". Dumper($fred); } print returns 1 when it works, so main will usually return 1. This means you exit with failure status no matter what. Potentially a bug. > The project is a web framework that allows for object types to be specified in the config file: Writing your own web framework, eh. I tried that once. http://catalyst.perl.org/ http://www.packtpub.com/catalyst-perl-web-application/book Finally, let me throw in a mention for things like Module::Pluggable::Object or MooseX::Object::Pluggable for writing plugins. Using a module is easier than doing it yourself, and they shield you from all the string evals :) Regards, Jonathan Rockway -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://mail.pm.org/pipermail/chicago-talk/attachments/20080116/45af62a0/attachment.bin From andy at petdance.com Wed Jan 16 21:57:50 2008 From: andy at petdance.com (Andy Lester) Date: Wed, 16 Jan 2008 23:57:50 -0600 Subject: [Chicago-talk] Perl 6 on Parrot is now called Rakudo Message-ID: <92CBA4A2-B2BE-4333-BFB3-8CB3D080C7A8@petdance.com> http://www.rakudo.org/2008/01/the-compiler-formerly-known-as.html [Patrick Michaud explains the newly discovered name for the Perl 6 on Parrot project. -- Andy] We've finally come up with a name for the Perl 6 on Parrot compiler, it's now "Rakudo Perl", or just "Rakudo" for short. This name was suggested by Damian Conway -- he writes: Some years ago, Con Wei Sensei introduced a new martial art: "The Way Of The Camel". Or, in Japanese: "Rakuda-do". This name quickly became abbreviated to "Rakudo", which happens to mean "paradise" in Japanese. Perhaps "rakudo" would suit, since: * * "Of The Camel" clearly connotes Perl * Perl on Parrot is definitely the Way * The name meets Hugo's Obscurity-for-Search criterion (at least for non-Japanese-language searches) * It's nevertheless a real word (in one language) * It may help us steal back mindshare from Ruby in its home market For the time being Rakudo will continue to live in the languages/ perl6/ subdirectory of the Parrot repository, and we'll continue to build the bytecode and executable as perl6.pbc and perl6(.exe). My current expectation is that someday Rakudo will live in its own repository separate from Parrot, and we can decide then if any file renaming needs to take place. So, we're now at the point where we can say that the term "Perl 6" strictly refers to a language specification, while terms such as "Pugs", "Rakudo", and "kp6" refer to implementations of Perl 6. Hopefully this will reduce some confusion. Several people have also inquired about a release numbering scheme for Rakudo. My current position on this topic is to postpone any decision until we start making releases that are separate from Parrot releases. I think a postponement here is especially appropriate since we're still in the "rapid expansion phase" of the implementation. In the meantime, whenever we need to reference a specific version of Rakudo we can use either a specific date or a subversion revision number from the Parrot repository. Diggs appreciated: http://digg.com/programming/Perl_6_on_Parrot_is_now_known_as_Rakudo Thanks, xoxo, Andy -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance From hucke at cynico.net Thu Jan 17 09:47:01 2008 From: hucke at cynico.net (Matt Hucke) Date: Thu, 17 Jan 2008 11:47:01 -0600 Subject: [Chicago-talk] calling functions in a package by its name In-Reply-To: <1200514049.10183.72.camel@bar.jrock.us> References: <478E5200.4060406@cynico.net> <1200514049.10183.72.camel@bar.jrock.us> Message-ID: <478F9495.2030502@cynico.net> >> sub getConfig # public API, implemented by lots of similar classes >> { >> return \%secretStuff; >> } > > First off %secretStuff isn't secret, it's a package variable. Right; what I was trying to show was that the dynamically-loaded module might store configuration info in any arbitrary unknown place it wants, but would be required to always have a function (getConfig() or somesuch) that would return it. >> my $prog = "use $classname;"; >> eval $prog; die("eval '$prog' failed with " . $@ ) if ($@); > > You do have to use string eval to load the class. require is better > than use here, though. (Do you want $class->import to be called? Not > for classes, usually.) OK, I'll give eval "require.." a try. It definitely should not import things into the caller's namespace - this thing is basically just an object factory. > Yes, of course we can :) And now you don't need eval. This applies to > methods also: > > my $foo = $class->$constructor(@args); Beautiful! And 'use strict' doesn't even complain. I was trying all sorts of convolutions of &{...} and $func=\&something and the like; didn't think that the solution would be so simple and elegant. > No, it's harmful because of: > my $class = "Foo; `rm -rf *`" True. I left it out of the demo program, but where I'm doing it for real I pass all the class names through a regex that cleans them up. > How about: > > my $class = 'Foo'; > eval "require $class"; > $class->can('new')->(); # Foo->new() I'll give that a try. > print returns 1 when it works, so main will usually return 1. This > means you exit with failure status no matter what. Potentially a bug. Sorry - the demo script was cobbled together in ten minutes, and I got sloppy. >> The project is a web framework that allows for object types to be specified in the config file: > Writing your own web framework, eh. I tried that once. > http://catalyst.perl.org/ I looked into Catalyst a few years back - it's quite impressive. But it was sufficiently different from the way I'd been doing things already - and from the mountain of legacy code on my employer's server - that I chose to instead do something I could ease into slowly. My "Baldrick" project thus evolved out of the way I'd been doing things already. Thanks for the advice - I'll be removing a few stringy evals from the production code today. -- hucke at cynico.net http://www.graveyards.com From brian.d.foy at gmail.com Fri Jan 18 01:27:12 2008 From: brian.d.foy at gmail.com (brian d foy) Date: Fri, 18 Jan 2008 03:27:12 -0600 Subject: [Chicago-talk] calling functions in a package by its name In-Reply-To: <1200514049.10183.72.camel@bar.jrock.us> References: <478E5200.4060406@cynico.net> <1200514049.10183.72.camel@bar.jrock.us> Message-ID: <2715accf0801180127h7c857218ie746839b3c764531@mail.gmail.com> On 1/16/08, Jonathan Rockway wrote: > First off %secretStuff isn't secret, it's a package variable. That > means it's global and anyone can get at it with % > MysteryClass::secretStuff. "my" can be package-scoped; use that > instead. my() isn't package scoped. That's the point of my; it's not something the package tracks. Also, "package" doesnt' create a scope. You can fake private class variables with my() variables by only having one package per file. In that case, it's the file scope that limits the my(). -- brian d foy http://www.pair.com/~comdog/ From lembark at wrkhors.com Mon Jan 21 13:01:59 2008 From: lembark at wrkhors.com (Steven Lembark) Date: Mon, 21 Jan 2008 16:01:59 -0500 Subject: [Chicago-talk] calling functions in a package by its name In-Reply-To: <478F9495.2030502@cynico.net> References: <478E5200.4060406@cynico.net> <1200514049.10183.72.camel@bar.jrock.us> <478F9495.2030502@cynico.net> Message-ID: <47950847.1060709@wrkhors.com> >>> my $prog = "use $classname;"; >>> eval $prog; die("eval '$prog' failed with " . $@ ) if ($@); >> You do have to use string eval to load the class. require is better >> than use here, though. (Do you want $class->import to be called? Not >> for classes, usually.) > > OK, I'll give eval "require.." a try. It definitely should not import things into the caller's > namespace - this thing is basically just an object factory. Actually, the "import" sub might be used to initialize some portion of the module itself at runtime, e.g., use Benchmark qw( :hireswallclock ); turns on the high-res wallclock feature in Benchmark. If you only use require then it may help to add something like: if( $package->can( 'import' ) ) { log_a_warning "Ignoring import in: $package"; } or if( $package->can( 'import' ) ) { $package->import; } >> How about: >> >> my $class = 'Foo'; >> eval "require $class"; >> $class->can('new')->(); # Foo->new() > > I'll give that a try. Note: foo->can(x)->() breaks if the package doesn't have a new coderef in their namespace (you'll be dispatching an undef). With minimal boilerplate this becomes a lot easeir to debug: if( my $sub = $class->can( 'new' ) ) { # "$class->$sub" gets you to the same place, # this avoids the indirect-object form and # makes it a bit more obvious that you exect # $sub to be a coderef. $sub->( $class ); } else { confess "Package missing 'new': $class" } It's also trivial to have the class return its value of $constructor, which allows for a more general: my $constructor = $classdata->{ constructor } || 'new'; if( my $sub = $class->can( $constructor ) ) { ... } else { confess "Bogus class: $class cannot $constructor" } > few stringy evals from the production code today. Always a good thing :-) -- Steven Lembark +1 888 359 3508 Workhorse Computing 85-09 90th St lembark at wrkhors.com Woodhaven, NY 11421 From joshua.mcadams at gmail.com Mon Jan 21 22:20:56 2008 From: joshua.mcadams at gmail.com (Joshua McAdams) Date: Tue, 22 Jan 2008 00:20:56 -0600 Subject: [Chicago-talk] Simple Photo Processing and Web Display with Perl (Meeting Tuesday!) Message-ID: <49d805d70801212220r2a47ca6fy9214b08db691e098@mail.gmail.com> Don't forget that Kent Cowgill will be presenting on Simple Photo Processing and Web Display with Perl at tomorrows meeting. Feel free to stop by 180 N La Salle 12th floor around 7pm. From kent at c2group.net Thu Jan 24 08:54:43 2008 From: kent at c2group.net (Kent Cowgill) Date: Thu, 24 Jan 2008 10:54:43 -0600 Subject: [Chicago-talk] Meeting Tuesday January 22nd In-Reply-To: <49d805d70801092011g3fd796eaqbfffd55f3d61659a@mail.gmail.com> References: <49d805d70801092011g3fd796eaqbfffd55f3d61659a@mail.gmail.com> Message-ID: <00720C17-9C23-43F4-A9A4-B9C6B53F5F0A@c2group.net> On Jan 9, 2008, at 10:11 PM, Joshua McAdams wrote: > Kent will be talking about "Simple Photo Processing and Web Display > with Perl". He has a small photo gallery on his website and shares > some steps he used in creating a nearly automatic workflow of getting > pictures from his camera to his gallery using Perl. FYI, I've posted the slides from this talk on slideshare.net: http://www.slideshare.net/kcowgill/simple-photo-processing-and-web- display-with-perl I also captured video and am working on getting it in a format conducive to downloading and sharing. -Kent Cowgill C2 Group, Inc. kent at c2group.net http://www.c2group.net 312.804.0160 From shawn.c.carroll at gmail.com Thu Jan 24 12:25:30 2008 From: shawn.c.carroll at gmail.com (Shawn Carroll) Date: Thu, 24 Jan 2008 14:25:30 -0600 Subject: [Chicago-talk] Dependency map Message-ID: My google fu is failing me. I remember a package that could take a perl module and produce a graph of its dependencies. I took a look at Graph-Dependencies but that isn't it as it only looks at CPAN modules. I've looked in PerlMonks, TPJ and TPR and cannot find what I remember. Anyone know what I'm talking about, or have I lost my mind. -- shawn.c.carroll at gmail.com Perl Programmer Soccer Referee From brian.d.foy at gmail.com Thu Jan 24 12:30:57 2008 From: brian.d.foy at gmail.com (brian d foy) Date: Thu, 24 Jan 2008 14:30:57 -0600 Subject: [Chicago-talk] Dependency map In-Reply-To: References: Message-ID: <2715accf0801241230g5e575565vf38f6d0f43910e50@mail.gmail.com> On 1/24/08, Shawn Carroll wrote: > My google fu is failing me. I remember a package that could take a > perl module and produce a graph of its dependencies. Are you thinking about CPANdeps? That was an article in the last TPR, and the source code is online. http://cpandeps.cantrell.org.uk/ -- brian d foy http://www.pair.com/~comdog/ From kent at c2group.net Thu Jan 24 12:32:18 2008 From: kent at c2group.net (Kent Cowgill) Date: Thu, 24 Jan 2008 14:32:18 -0600 Subject: [Chicago-talk] Dependency map In-Reply-To: References: Message-ID: On Jan 24, 2008, at 2:25 PM, Shawn Carroll wrote: > My google fu is failing me. I remember a package that could take a > perl module and produce a graph of its dependencies. I took a look at > Graph-Dependencies but that isn't it as it only looks at CPAN modules. > I've looked in PerlMonks, TPJ and TPR and cannot find what I > remember. Anyone know what I'm talking about, or have I lost my mind. > Could it be this: http://cpandeps.cantrell.org.uk/ -Kent Cowgill C2 Group, Inc. kent at c2group.net http://www.c2group.net 312.804.0160 From kent at c2group.net Thu Jan 24 12:32:18 2008 From: kent at c2group.net (Kent Cowgill) Date: Thu, 24 Jan 2008 14:32:18 -0600 Subject: [Chicago-talk] Dependency map In-Reply-To: References: Message-ID: On Jan 24, 2008, at 2:25 PM, Shawn Carroll wrote: > My google fu is failing me. I remember a package that could take a > perl module and produce a graph of its dependencies. I took a look at > Graph-Dependencies but that isn't it as it only looks at CPAN modules. > I've looked in PerlMonks, TPJ and TPR and cannot find what I > remember. Anyone know what I'm talking about, or have I lost my mind. > Could it be this: http://cpandeps.cantrell.org.uk/ -Kent Cowgill C2 Group, Inc. kent at c2group.net http://www.c2group.net 312.804.0160 From jon-andy-lester-sucks at jrock.us Thu Jan 24 12:51:06 2008 From: jon-andy-lester-sucks at jrock.us (Jonathan Rockway) Date: Thu, 24 Jan 2008 14:51:06 -0600 Subject: [Chicago-talk] Dependency map In-Reply-To: (Shawn Carroll's message of "Thu\, 24 Jan 2008 14\:25\:30 -0600") References: Message-ID: <873asn0wxx.fsf@bar.jrock.us> "Shawn Carroll" writes: > My google fu is failing me. I remember a package that could take a > perl module and produce a graph of its dependencies. I took a look at > Graph-Dependencies but that isn't it as it only looks at CPAN modules. > I've looked in PerlMonks, TPJ and TPR and cannot find what I > remember. Anyone know what I'm talking about, or have I lost my mind. Module::ScanDeps generates a dependency spanning tree for an arbitrary (locally-available) module. If you want a graph, you will have to invoke ScanDeps recursively. Regards, Jonathan Rockway From shawn.c.carroll at gmail.com Thu Jan 24 13:00:45 2008 From: shawn.c.carroll at gmail.com (Shawn Carroll) Date: Thu, 24 Jan 2008 15:00:45 -0600 Subject: [Chicago-talk] Dependency map In-Reply-To: <873asn0wxx.fsf@bar.jrock.us> References: <873asn0wxx.fsf@bar.jrock.us> Message-ID: On Jan 24, 2008 2:51 PM, Jonathan Rockway wrote: > "Shawn Carroll" writes: > > > My google fu is failing me. I remember a package that could take a > > perl module and produce a graph of its dependencies. I took a look at > > Graph-Dependencies but that isn't it as it only looks at CPAN modules. > > I've looked in PerlMonks, TPJ and TPR and cannot find what I > > remember. Anyone know what I'm talking about, or have I lost my mind. > > Module::ScanDeps generates a dependency spanning tree for an arbitrary > (locally-available) module. If you want a graph, you will have to > invoke ScanDeps recursively. > > Regards, > Jonathan Rockway Sam McGee pointed me to Module::Dependency::Grapher, which is what I was wanting -- shawn.c.carroll at gmail.com Perl Programmer Soccer Referee From dave at obtiva.com Wed Jan 30 10:51:55 2008 From: dave at obtiva.com (Dave Hoover) Date: Wed, 30 Jan 2008 12:51:55 -0600 Subject: [Chicago-talk] The JavaScript Renaissance Part II: The Browser Message-ID: <11c8704e0801301051ne3bfef0m4b17557fcf73e4ed@mail.gmail.com> We're going to continue our focus on JavaScript for our Febrary meeting in Wheaton. Fred Polgardy will continue his JavaScript Renaissance series. When: Tuesday, Feb 12, 2008, 7-9 PM Where: Wheaton, IIT - Rice Campus Who: Frederick Polgardy What: The JavaScript Renaissance Part II: The Browser What comes to mind when think of JavaScript? Broken web sites, browser incompatibilities, and brittle spaghetti code? It doesn't have to be this way anymore! Last time we learned about some powerful features of JavaScript, the language. In Part II of our exploration, we'll be focusing on JavaScript in its native habitat -- the Web browser. We'll look at the Document Object Model, and how it enables us to dynamically create and modify web page content. We'll learn about the DOM Event Model, and how it gives us the capability to capture and respond to user input. We'll also take a brief look at XMLHttpRequest, the technology that makes Ajax possible, and see how to communicate with the server without ever leaving the page. Along the way, we'll grapple with browser incompatibility issues, and see how libraries like Prototype and jQuery help us navigate the waters. More information and directions can be found at http://chicago.pm.org/meetings/ Let me know if you have ideas for other talks in 2008. I'd definitely like to get back to Perl, but haven't heard from anyone about what they'd like to hear or talk about. Best, Dave Hoover //obtiva: Agility applied. Software delivered. From richard at rushlogistics.com Thu Jan 31 07:13:43 2008 From: richard at rushlogistics.com (Richard Reina) Date: Thu, 31 Jan 2008 07:13:43 -0800 (PST) Subject: [Chicago-talk] Removing "." from a string? Message-ID: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> Does anyone know an easy way to remove "."s from a string like 192.168.2.16 so I get 192168216? Substring seems cumbersome and does not account for length between dots. Thanks for any help. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080131/ce85fd41/attachment.html From don at drakeconsult.com Thu Jan 31 07:16:26 2008 From: don at drakeconsult.com (Don Drake) Date: Thu, 31 Jan 2008 09:16:26 -0600 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> Message-ID: <0ACD9E9A-F818-49CA-B70E-E04619753A7D@drakeconsult.com> #!/usr/bin/perl my $ip='192.168.2.16'; $ip=~s/\.//g; print $ip."\n"; -Don -- Don Drake www.drakeconsult.com www.maillaunder.com 312-560-1574 800-733-2143 On Jan 31, 2008, at 9:13 AM, Richard Reina wrote: > Does anyone know an easy way to remove "."s from a string like > 192.168.2.16 > > so I get 192168216? Substring seems cumbersome and does not account > for length between dots. > > Thanks for any help. > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk From jtk at depaul.edu Thu Jan 31 07:31:05 2008 From: jtk at depaul.edu (John Kristoff) Date: Thu, 31 Jan 2008 09:31:05 -0600 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> Message-ID: <20080131153105.D98C6229@condor.depaul.edu> On Thu, 31 Jan 2008 07:13:43 -0800 (PST) Richard Reina wrote: > Does anyone know an easy way to remove "."s from a string like > 192.168.2.16 > > so I get 192168216? Substring seems cumbersome and does not account for length between dots. echo 192.168.2.16 | perl -pe 's/\.//g' John From arodland at comcast.net Thu Jan 31 10:00:14 2008 From: arodland at comcast.net (Andrew Rodland) Date: Thu, 31 Jan 2008 12:00:14 -0600 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <20080131153105.D98C6229@condor.depaul.edu> References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> <20080131153105.D98C6229@condor.depaul.edu> Message-ID: <200801311200.14512.arodland@comcast.net> On Thursday 31 January 2008 09:31:05 am John Kristoff wrote: > On Thu, 31 Jan 2008 07:13:43 -0800 (PST) > > Richard Reina wrote: > > Does anyone know an easy way to remove "."s from a string like > > 192.168.2.16 > > > > so I get 192168216? Substring seems cumbersome and does not account for > > length between dots. > > echo 192.168.2.16 | perl -pe 's/\.//g' Bah, kids these days... haven't been tought not to use s/// when tr/// will do. perl -pe 'y/.//d' Note: kidding, really... but it had to be said ;) Andrew From lembark at wrkhors.com Thu Jan 31 12:14:06 2008 From: lembark at wrkhors.com (Steven Lembark) Date: Thu, 31 Jan 2008 15:14:06 -0500 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> Message-ID: <47A22C0E.8030603@wrkhors.com> Richard Reina wrote: > Does anyone know an easy way to remove "."s from a string like > 192.168.2.16 > > so I get 192168216? Substring seems cumbersome and does not account for > length between dots. > > Thanks for any help. Here are four progessively more ridiculous solutions: $dotted_quad =~ s/\D//g; my $digits = join '', split /\D+/, $dotted_quad; my $digits = join '', $dotted_quad =~ m{ (\d+) }gx; while( ( my $i = index $dotted_quad, '.' ) > 0 ) { substr $dotted_quad, $i, 1, ''; } though the last one may actually be the fastest due to the lack of recursion and extra data structures. -- Steven Lembark +1 888 359 3508 Workhorse Computing 85-09 90th St lembark at wrkhors.com Woodhaven, NY 11421 From jtk at depaul.edu Thu Jan 31 12:20:07 2008 From: jtk at depaul.edu (John Kristoff) Date: Thu, 31 Jan 2008 14:20:07 -0600 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <200801311200.14512.arodland@comcast.net> References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> <20080131153105.D98C6229@condor.depaul.edu> <200801311200.14512.arodland@comcast.net> Message-ID: <20080131202007.E05F1228@condor.depaul.edu> On Thu, 31 Jan 2008 12:00:14 -0600 Andrew Rodland wrote: > Bah, kids these days... haven't been tought not to use s/// when tr/// will > do. Other than saving one keystroke, is there anything specifically more correct or better to using tr/// there than using perl's re? John From richard at rushlogistics.com Thu Jan 31 12:15:19 2008 From: richard at rushlogistics.com (richard at rushlogistics.com) Date: Thu, 31 Jan 2008 20:15:19 +0000 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <47A22C0E.8030603@wrkhors.com> References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com><47A22C0E.8030603@wrkhors.com> Message-ID: <976596905-1201810599-cardhu_decombobulator_blackberry.rim.net-1831645690-@bxe111.bisx.prod.on.blackberry> Thanks for all the replies. They were all good. Sent via BlackBerry from T-Mobile -----Original Message----- From: Steven Lembark Date: Thu, 31 Jan 2008 15:14:06 To:"Chicago.pm chatter" Subject: Re: [Chicago-talk] Removing "." from a string? Richard Reina wrote: > Does anyone know an easy way to remove "."s from a string like > 192.168.2.16 > > so I get 192168216? Substring seems cumbersome and does not account for > length between dots. > > Thanks for any help. Here are four progessively more ridiculous solutions: $dotted_quad =~ s/\D//g; my $digits = join '', split /\D+/, $dotted_quad; my $digits = join '', $dotted_quad =~ m{ (\d+) }gx; while( ( my $i = index $dotted_quad, '.' ) > 0 ) { substr $dotted_quad, $i, 1, ''; } though the last one may actually be the fastest due to the lack of recursion and extra data structures. -- Steven Lembark +1 888 359 3508 Workhorse Computing 85-09 90th St lembark at wrkhors.com Woodhaven, NY 11421 _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk From Andy_Bach at wiwb.uscourts.gov Thu Jan 31 12:24:59 2008 From: Andy_Bach at wiwb.uscourts.gov (Andy_Bach at wiwb.uscourts.gov) Date: Thu, 31 Jan 2008 14:24:59 -0600 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <47A22C0E.8030603@wrkhors.com> Message-ID: Did somebody *not* say "benchmark" ;-> # perl /tmp/dot.pl 10000000 Benchmark: timing 10000000 iterations of joinmatch, splitjoin, subst, whileindex... joinmatch: 4 wallclock secs ( 3.09 usr + 0.00 sys = 3.09 CPU) @ 3236245.95/s (n=10000000) splitjoin: 3 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) @ 3095975.23/s (n=10000000) subst: 0 wallclock secs ( 0.91 usr + 0.00 sys = 0.91 CPU) @ 10989010.99/s (n=10000000) whileindex: 3 wallclock secs ( 2.73 usr + 0.00 sys = 2.73 CPU) @ 3663003.66/s (n=10000000) use Benchmark qw(:all) ; # Use Perl code in strings... # timethese($count, { # 'Name1' => '...code1...', my $dotted_quad = '146.126.45.123'; my $count = shift || 10000; timethese($count, { 'subst' => "\$dotted_quad =~ s/\D//g;", 'splitjoin' => "my \$digits = join '', split /\D+/, \$dotted_quad;", 'joinmatch' => "my \$digits = join '', \$dotted_quad =~ m{ (\d+) }gx;", 'whileindex' => "while( ( my \$i = index \$dotted_quad, '.' ) > 0 ) { substr \$dotted_quad, \$i, 1, ''; }; ", }); a Andy Bach Systems Mangler Internet: andy_bach at wiwb.uscourts.gov VOICE: (608) 261-5738 FAX 264-5932 "The Microsoft Exchange Information Store service depends on the Microsoft Exchange Directory service which failed to start because of the following error: The operation completed successfully." (actual MSE error msg) From Andy_Bach at wiwb.uscourts.gov Thu Jan 31 12:34:18 2008 From: Andy_Bach at wiwb.uscourts.gov (Andy_Bach at wiwb.uscourts.gov) Date: Thu, 31 Jan 2008 14:34:18 -0600 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <976596905-1201810599-cardhu_decombobulator_blackberry.rim.net-1831645690-@bxe111.bisx.prod.on.blackberry> Message-ID: Forgot tr: Benchmark: timing 10000000 iterations of joinmatch, splitjoin, subst, tr, whileindex... joinmatch: 3 wallclock secs ( 3.06 usr + 0.00 sys = 3.06 CPU) @ 3267973.86/s (n=10000000) splitjoin: 3 wallclock secs ( 3.92 usr + 0.00 sys = 3.92 CPU) @ 2551020.41/s (n=10000000) subst: 1 wallclock secs ( 0.90 usr + 0.00 sys = 0.90 CPU) @ 11111111.11/s (n=10000000) tr: 1 wallclock secs ( 1.51 usr + 0.00 sys = 1.51 CPU) @ 6622516.56/s (n=10000000) whileindex: 2 wallclock secs ( 2.85 usr + 0.00 sys = 2.85 CPU) @ 3508771.93/s (n=10000000) Andy Bach Systems Mangler Internet: andy_bach at wiwb.uscourts.gov VOICE: (608) 261-5738 FAX 264-5932 "The Microsoft Exchange Information Store service depends on the Microsoft Exchange Directory service which failed to start because of the following error: The operation completed successfully." (actual MSE error msg) From merlyn at stonehenge.com Thu Jan 31 15:09:46 2008 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Thu, 31 Jan 2008 15:09:46 -0800 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <20080131202007.E05F1228@condor.depaul.edu> (John Kristoff's message of "Thu, 31 Jan 2008 14:20:07 -0600") References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> <20080131153105.D98C6229@condor.depaul.edu> <200801311200.14512.arodland@comcast.net> <20080131202007.E05F1228@condor.depaul.edu> Message-ID: <863asdzj5x.fsf@blue.stonehenge.com> >>>>> "John" == John Kristoff writes: John> Other than saving one keystroke, is there anything specifically more John> correct or better to using tr/// there than using perl's re? Speed. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! From e.ellington at gmail.com Thu Jan 31 15:24:32 2008 From: e.ellington at gmail.com (Eric Ellington) Date: Thu, 31 Jan 2008 17:24:32 -0600 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <863asdzj5x.fsf@blue.stonehenge.com> References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> <20080131153105.D98C6229@condor.depaul.edu> <200801311200.14512.arodland@comcast.net> <20080131202007.E05F1228@condor.depaul.edu> <863asdzj5x.fsf@blue.stonehenge.com> Message-ID: > subst: 0 wallclock secs ( 0.91 usr + 0.00 sys = 0.91 CPU) @ >10989010.99/s (n=10000000) > > tr: 1 wallclock secs ( 1.51 usr + 0.00 sys = 1.51 CPU) @ >6622516.56/s (n=10000000) > > 'subst' => "\$dotted_quad =~ s/\D//g;", > I am confused. Didn't Andy Bach show that s/// was the quickest in this case? In what case would tr be quicker? Eric On Jan 31, 2008 5:09 PM, Randal L. Schwartz wrote: > >>>>> "John" == John Kristoff writes: > > John> Other than saving one keystroke, is there anything specifically more > John> correct or better to using tr/// there than using perl's re? > > Speed. > > -- > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. > See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -- Eric Ellington e.ellington at gmail.com From zrusilla at mac.com Thu Jan 31 15:26:24 2008 From: zrusilla at mac.com (Elizabeth Cortell) Date: Thu, 31 Jan 2008 15:26:24 -0800 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: <20080131202007.E05F1228@condor.depaul.edu> References: <629719.64624.qm@web604.biz.mail.mud.yahoo.com> <20080131153105.D98C6229@condor.depaul.edu> <200801311200.14512.arodland@comcast.net> <20080131202007.E05F1228@condor.depaul.edu> Message-ID: <97FA1CD1-0117-1000-8A0C-FA8597AD2430-Webmail-10014@mac.com> >> Bah, kids these days... haven't been tought not to use s/// when tr/// will >> do. > >Other than saving one keystroke, is there anything specifically more >correct or better to using tr/// there than using perl's re? tr/// is a compile-time operator. If I understand correctly, it will not be recompiled with each invocation, and you avoid the overhead of awakening the regular-expression dragon, er, engine. From Andy_Bach at wiwb.uscourts.gov Thu Jan 31 17:26:25 2008 From: Andy_Bach at wiwb.uscourts.gov (Andy_Bach at wiwb.uscourts.gov) Date: Thu, 31 Jan 2008 19:26:25 -0600 Subject: [Chicago-talk] Removing "." from a string? In-Reply-To: Message-ID: > Benchmark: timing 10000000 iterations of joinmatch, splitjoin, subst, tr, whileindex... joinmatch: 3 wallclock secs ( 3.06 usr + 0.00 sys = 3.06 CPU) @ 3267973.86/s (n=10000000) splitjoin: 3 wallclock secs ( 3.92 usr + 0.00 sys = 3.92 CPU) @ 2551020.41/s (n=10000000) subst: 1 wallclock secs ( 0.90 usr + 0.00 sys = 0.90 CPU) @ 11111111.11/s (n=10000000) tr: 1 wallclock secs ( 1.51 usr + 0.00 sys = 1.51 CPU) @ 6622516.56/s (n=10000000) whileindex: 2 wallclock secs ( 2.85 usr + 0.00 sys = 2.85 CPU) @ 3508771.93/s (n=10000000) Just a test: Benchmark: timing 10000000 iterations of joinmatch, splitjoin, subst, tr, whileindex... joinmatch: 4 wallclock secs ( 3.04 usr + 0.00 sys = 3.04 CPU) @ 3289473.68/s (n=10000000) splitjoin: 4 wallclock secs ( 4.03 usr + 0.00 sys = 4.03 CPU) @ 2481389.58/s (n=10000000) subst: 2 wallclock secs ( 1.02 usr + 0.00 sys = 1.02 CPU) @ 9803921.57/s (n=10000000) tr: 3 wallclock secs ( 1.49 usr + 0.00 sys = 1.49 CPU) @ 6711409.40/s (n=10000000) whileindex: 4 wallclock secs ( 2.90 usr + 0.00 sys = 2.90 CPU) @ 3448275.86/s (n=10000000) and w/o invoking the 'RE Beast' I just tested tr: Benchmark: timing 10000000 iterations of tr... tr: 1 wallclock secs ( 1.39 usr + 0.00 sys = 1.39 CPU) @ 7194244.60/s (n=10000000) Benchmark: timing 10000000 iterations of tr... tr: 1 wallclock secs ( 1.27 usr + 0.00 sys = 1.27 CPU) @ 7874015.75/s (n=10000000) I know somewhere it says tr/// is the fastest route but the simplicity of the subst RE maybe part of the anomalous result. Tried: Benchmark: timing 10000000 iterations of joinmatch, substD, substcharclas, substdot, tr... joinmatch: 2 wallclock secs ( 2.84 usr + 0.00 sys = 2.84 CPU) @ 3521126.76/s (n=10000000) substD: 1 wallclock secs ( 1.01 usr + 0.00 sys = 1.01 CPU) @ 9900990.10/s (n=10000000) substcharclas: 1 wallclock secs ( 1.28 usr + 0.00 sys = 1.28 CPU) @ 7812500.00/s (n=10000000) substdot: 2 wallclock secs ( 1.29 usr + 0.00 sys = 1.29 CPU) @ 7751937.98/s (n=10000000) tr: 1 wallclock secs ( 1.27 usr + 0.00 sys = 1.27 CPU) @ 7874015.75/s (n=10000000) and \D still beats them all. Huh. a Andy Bach Systems Mangler Internet: andy_bach at wiwb.uscourts.gov VOICE: (608) 261-5738 FAX 264-5932 "The Microsoft Exchange Information Store service depends on the Microsoft Exchange Directory service which failed to start because of the following error: The operation completed successfully." (actual MSE error msg)