From jhannah at omnihotels.com Mon May 9 07:46:28 2005 From: jhannah at omnihotels.com (Jay Hannah) Date: Mon, 9 May 2005 09:46:28 -0500 Subject: [Omaha.pm] Another 20s hack Message-ID: <200505091445.j49EjumD029507@omares-email.omnihotels.com> Given a list of tables, kick out a bunch of SQL statements. j while () { chomp; #print "select count(*) from $_ where prop = 'NYCCAR';\n"; #print "unload to $_.unl select * from $_ where prop = 'NYCCAR';\n"; print "delete from $_ where prop = 'NYCCAR';\n"; } __DATA__ resfile1 resfile1_ar resfile_comment resfile_comment_ar resfile_conf resfile_gtd resfile_gtd_ar resfile_lookup resfile_master resfile_master_ar resfile_rates resfile_rates_ar resfile_sh_rate resfile_sh_rate_ar resfile_smaster resfile_smaster_ar resfile_srq resfile_srq_ar resfile_ta resfile_ta_ar From jhannah at omnihotels.com Mon May 9 07:51:00 2005 From: jhannah at omnihotels.com (Jay Hannah) Date: Mon, 9 May 2005 09:51:00 -0500 Subject: [Omaha.pm] Template Toolkit & CGI::Carp Message-ID: <200505091450.j49EoRmD009963@omares-email.omnihotels.com> Bummer. I do this all the time: use CGI::Carp qw( fatalsToBrowser ); It's awfully handy. I'm a Template Toolkit newb, but I'd expect this to work: my $template = Template->new({ INCLUDE_PATH => $self->get_INCLUDE_PATH, INTERPOLATE => 1, }); $template->process($file,$vars) || die $template->error; But it doesn't. Somehow CGI::Carp can't catch that die (the die output ends up the Apache log). (Maybe this has something to do with it? http://template-toolkit.org/pipermail/templates/2001-August/001399.html) So the poorest poor man's CGI::Carp ever: $template->process($file,$vars) || print "

" . $template->error . "

"; It works. Grin, j From glim at mycybernet.net Tue May 10 20:09:00 2005 From: glim at mycybernet.net (Gerard Lim) Date: Tue, 10 May 2005 23:09 -0400 Subject: [Omaha.pm] Yet Another Perl Conference final details Message-ID: Hi everyone... There have been some recent developments on the YAPC::NA front, and it has been suggested to us that a reminder might be helpful to some people, so here's a quick summary of the event. Summary ------- YAPC::NA 2005 (Yet Another Perl Conference, North America) in Toronto, Canada, Monday - Wednesday 27 - 29, June 2005 Home page: http://yapc.org/America/ Conference Location: http://89chestnut.com/ A facility of the University of Toronto Accommodations -------------- Normally registration information would come first, but accommodations are the bottleneck -- our main group reservation (at the conference hotel) expires at the end of the week, and as the conference approaches it will be extremely difficult to find a hotel anywhere in the city. Info on how to book at: http://yapc.org/America/accommodations-2005.shtml Registration ------------ Register now! :-) We are on track to break attendance records at YAPC::NA this year, and we could even sell out before the conference starts. The price for the full 3 days is USD$85. We keep it insanely low through many generous sponsorships and the all-volunteer organizational and speaking crews. Registration info: http://yapc.org/America/register-2005.shtml Direct registration link: http://donate.perlfoundation.org/index.pl?node=registrant%20info&conference_id=423 Conference Speaking Schedule ---------------------------- We've got an excellent selection of talks and speakers for Perl programmers of all levels, beginner through expert. We are fortunate enough to have presentations coming from some of the most recognizable names in Perl programming today, including Larry Wall, Chip Salzenberg, Dan Sugalski, Autrijus Tang and brian d foy. Summary -- http://yapc.org/America/schedule-2005/summary.html Day 1 -- http://yapc.org/America/schedule-2005/day1.html Day 2 -- http://yapc.org/America/schedule-2005/day2.html Day 3 -- http://yapc.org/America/schedule-2005/day3.html Lightning Talks --------------- These short (5 minutes each) talks, presented by the conference attendees, are a YAPC tradition. If you're interested please read more about them and sign up: http://www.justanotherperlhacker.org/lightning/ [ This message was sent by Gerard Lim on behalf of the YAPC::NA 2005 Conference organizing committee of the Toronto Perl Mongers. Thanks for your patience and support. ] From jay at jays.net Mon May 16 15:16:23 2005 From: jay at jays.net (Jay Hannah) Date: Mon, 16 May 2005 17:16:23 -0500 Subject: [Omaha.pm] Mtg this Thr 5/19 @ 7pm. No June mtg. Message-ID: <9b0be9044596f2c1c1f607be9ee8a584@jays.net> Meeting this Thr @ 7pm! http://omaha.pm.org/ If nothing else is suggested I'll be going over some Template Toolkit wisdom/hackery/stupidity I've been working on lately. I like hearing myself talk, but does anyone else use Perl for something and is willing to demo it? If you've seen my demos you know that not a lot of prep work, professionalism, nor public speaking skills are required. Any takers? Any subject matter requests? Challenges people are facing? I'd also like to talk about Perl activism at the meeting. See if we can get more new folks involved. Let local CS professors (UNO, Creighton, Metro?) know we're out here if students are looking for extra help or anything...? Thoughts? A guy got me into Perl back in 1993, I'd like to reciprocate. They can take or leave Perl, but it'd be nice to let more young folk (da yoots) (or newly computer savvy folk) know we're out here as one option. There will be no June meeting, as I'll be in Taiwan for 2 weeks. Unless, of course, someone wants to organize a meeting without me -- feel free. I'll try to swing by the 2 (?) Taiwan Perl Monger groups in Taiwan and say hi (in English... or Perl) on behalf of Omaha.pm. -grin- j From jay at jays.net Tue May 17 15:12:12 2005 From: jay at jays.net (Jay Hannah) Date: Tue, 17 May 2005 17:12:12 -0500 Subject: [Omaha.pm] More 10m hackery - date format conversion in flat files for DB load Message-ID: <26c4a38b5e3140000838dd9a1fdbc421@jays.net> Problem: You have a database unload file like this: > cat in qweq|qwedqd|12/03/2003|12321|12/01/2002|XXX| qweq|qwedqd|12/03/2003|12321|12/01/2002|XXX| ...etc... But you need those pesky date fields to look like this so MS-SQL will load it (bcp): qweq|qwedqd|2003-12-03 00:00:00|12321|2002-12-01 00:00:00|XXX qweq|qwedqd|2003-12-03 00:00:00|12321|2002-12-01 00:00:00|XXX ...etc... Solutions: A hard coded solution to convert the first date only: ======================================================= #!/usr/bin/perl open (IN, "tndns_dly_arr.unl"); while () { chomp; @l = split /\|/; @d = split /\//, $l[2]; $l[2] = sprintf("%04d-%02d-%02d 00:00:00", @d[2,0,1]); print join "|", @l; print "|\n"; } close IN; ======================================================= An argument based version that accepts an arbitrary array indicating which fields should be converted: ======================================================= > cat j.pl while () { chomp; $line = $_; foreach (@ARGV) { $line = conv_date($line, $_); } print "$line\n"; } sub conv_date { my ($line, $pos) = @_; @l = split /\|/, $line; @d = split /\//, $l[$pos]; $l[$pos] = sprintf("%04d-%02d-%02d 00:00:00", @d[2,0,1]); my $ret = join "|", @l; return $ret; } ======================================================= You'd use the param version like this: > cat in | perl j.pl 2 4 qweq|qwedqd|2003-12-03 00:00:00|12321|2002-12-01 00:00:00|XXX qweq|qwedqd|2003-12-03 00:00:00|12321|2002-12-01 00:00:00|XXX > ( Then load your converted data into MS-SQL w/ bcp: bcp dss.dbo.tndns_dly_arr in t.unl -U sa -c -t "|" -r "|\n" -m 1000000 ) j From jhannah at omnihotels.com Thu May 19 11:10:57 2005 From: jhannah at omnihotels.com (Jay Hannah) Date: Thu, 19 May 2005 13:10:57 -0500 Subject: [Omaha.pm] 30m hack - survey log de-duper Message-ID: <200505191810.j4JIAJnn024299@omares-email.omnihotels.com> Given a log like this: 2005-05-19 11:31:09|CRPTWR|D2|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|| 2005-05-19 11:31:57|CRPTWR|D6|2|1|1|4|3|3|3|3|4|3|4|4|4|4|4|3|1|1|1|4|3|4|1|4|4|3|2|1|4|| 2005-05-19 11:32:31|CRPTWR|D3|4|4|3|4|4|4|3|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|| 2005-05-19 11:33:01|CRPTWR|D10|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|| from an online survey, detect and remove any times that people may have double-clicked the submit button creating identical rows. If you find an identical row (ignoring the datetime stamp) logged within 10s of its identical counterpart, its a dupe. Remove it. Solution: #!/usr/bin/perl use Date::Calc qw( Delta_DHMS ); open (IN, "aos.log"); open (OUTGOOD, ">aos.log.good"); open (OUTDUPE, ">aos.log.dupes"); while () { # print; chomp; my $line = $_; my $key = $line; $key =~ s/.*?\|//; if ($keys{$key}) { #print "$keys{$key}\n"; #print "$line\n"; #print " dupe!?"; if (seconds_elapsed($keys{$key}, $line) > 10) { #print " no. There was at least 10s elapsed.\n"; print OUTGOOD "$line\n"; } else { #print " YES! This is a dupe!!\n"; print OUTDUPE "$line\n"; } } else { print OUTGOOD "$line\n"; } $keys{$key} = $line; } close IN; sub seconds_elapsed { my ($str1, $str2) = @_; $str1 =~ s/\|.*//; $str2 =~ s/\|.*//; my @delta = Delta_DHMS((split /\D/, $str1), (split /\D/, $str2)); my $ret = $delta[0] * 24 * 60 * 60 + # Days -> seconds $delta[1] * 60 * 60 + # Hours -> seconds $delta[2] * 60 + # Minutes -> seconds $delta[3]; # Seconds # print "$str1 -> $str2 = $ret seconds elapsed\n"; return $ret; } Cheers, j From jay at jays.net Wed May 25 13:49:25 2005 From: jay at jays.net (Jay Hannah) Date: Wed, 25 May 2005 15:49:25 -0500 Subject: [Omaha.pm] debugger - dump the output of x $self to a file Message-ID: <122e0574438e9ca3b927a457363605ce@jays.net> Just switch your pager to a redirect to a file: DB<8> o pager=>/tmp/j.txt pager = '>/tmp/j.txt' DB<9> | x $self Now you've got a /tmp/j.txt file containing what 'x $self' would have shown. Sweet. j From jay at jays.net Fri May 27 08:56:44 2005 From: jay at jays.net (Jay Hannah) Date: Fri, 27 May 2005 10:56:44 -0500 Subject: [Omaha.pm] unless ($current_count % 100) { Message-ID: Laugh... This $current_count++; unless ($current_count % 100) { $self->logger->info(" $current_count rows done..."); } is just an evil way of writing $current_count++; if ($current_count % 100 == 0) { $self->logger->info(" $current_count rows done..."); } I think the latter is much more readable. Yes/no? j From tedkat at gmail.com Fri May 27 09:04:09 2005 From: tedkat at gmail.com (Theodore Katseres) Date: Fri, 27 May 2005 11:04:09 -0500 Subject: [Omaha.pm] unless ($current_count % 100) { In-Reply-To: References: Message-ID: On 5/27/05, Jay Hannah wrote: > > Laugh... This > > $current_count++; > unless ($current_count % 100) { > $self->logger->info(" $current_count rows done..."); > } > > is just an evil way of writing > > $current_count++; > if ($current_count % 100 == 0) { > $self->logger->info(" $current_count rows done..."); > } > > I think the latter is much more readable. Yes/no? About the same I'd say :) But then again I'm Evil. -- Ted Katseres From jhannah at omnihotels.com Fri May 27 10:45:08 2005 From: jhannah at omnihotels.com (Jay Hannah) Date: Fri, 27 May 2005 12:45:08 -0500 Subject: [Omaha.pm] another hack -- s/\|$key\|/\|$c{$key}\|/; Message-ID: <200505271744.j4RHiRnn012355@omares-email.omnihotels.com> Given a survey log like this: 2005-05-12 09:07:42|MONDTN|D10|2|3|3|2|2|4|2|2|1|1|2|2|1|1|4|2|2|3|3|3|2|4|4|4|4|4|3|2|3|| 2005-05-12 09:08:54|MONDTN|D16|4|3|4|4|4|4|4|4|4|4|4|4|4|4|4|4|4|3|4|4|4|4|4|4|4|4|4|4|4|| 2005-05-12 09:09:56|MONDTN|D16|4|3|4|4|4|3|4|4|3||3|4|3|4|4||4|3|4|4|4|4|4|4|4|3|3|4|3|| Where D10, D16 (etc) are department indicators; and given that you just realized that you wrote the survey thing wrong and need to switch out departments indicators: change all D20's to D14, all D14's to D15, etc. Solution: --- my %c = ( 'D20' => 'D14', 'D14' => 'D15', 'D15' => 'D16', 'D16' => 'D17', 'D17' => 'D18', 'D18' => 'D19', 'D19' => 'D20' ); LINE: while (<>) { foreach $key (keys %c) { if (/\|$key\|/) { s/\|$key\|/\|$c{$key}\|/; print; next LINE; } } print; } --- Bonus points: My first solution just did something like this: s/\|D20\|/\|D14\|/; s/\|D14\|/\|D15\|/; s/\|D15\|/\|D16\|/; s/\|D16\|/\|D17\|/; etc... Why was that solution doomed to fail? j From jay at jays.net Fri May 27 15:37:02 2005 From: jay at jays.net (Jay Hannah) Date: Fri, 27 May 2005 17:37:02 -0500 Subject: [Omaha.pm] Perl, XML, Oracle Opportunity in the Kansas City Area In-Reply-To: <002901c56208$ddc012a0$1500000a@homepbw6s7ykbs> References: <002901c56208$ddc012a0$1500000a@homepbw6s7ykbs> Message-ID: <1e079f70a31cfa3696c40113bb77874e@jays.net> From the help wanted department. j On May 26, 2005, at 10:37 AM, Lynn Leikam wrote: > Jay, > Thank you for your time this week. I wanted to follow up with you > regarding the permanent opportunity we have in Kansas City, MO. ?We > are looking to hire an Information Technology Professional with 3-5 > years in Perl, XML and Oracle. ?Excellent financial package for the > right candidate. > ? > Thank you for your time! > ? > Best regards, > ? > Lynn Leikam > ECCO Select > Phone 816-960-3800 ext. 16 > Toll Free 888-567-ECCO > Fax 816-960-3804 > Cell 913-522-8048 > ? > WEB eccoselect.com > Excellence in Information Consulting Services > Minority/Women Owned Business > Certified 8a Business From dthacker9 at cox.net Sat May 28 23:15:26 2005 From: dthacker9 at cox.net (Dave Thacker) Date: Sun, 29 May 2005 01:15:26 -0500 Subject: [Omaha.pm] Getopt::Long and opt_ variables Message-ID: <200505290115.26995.dthacker9@cox.net> In the second edition camel (on page 448), it says that" "If no linkage is explicitly specified and no hash ref is passed, GetOptions() will put the value of in a global variable named after the option preceded by opt_..." Is this automagically done? This example doesn't seen to work . #!/usr/bin/perl -w use strict; use Getopt::Long; my $opt_place; &GetOptions("place=s"); print "Hello! $opt_place\n"; dthacker at fluffy:~/dev/dwofl/bin> ./test2.pl -place World Use of uninitialized value in concatenation (.) or string at ./test2.pl line 9. Hello! DT From omaha-pm at jbisbee.com Sun May 29 06:12:04 2005 From: omaha-pm at jbisbee.com (Jeff Bisbee) Date: Sun, 29 May 2005 09:12:04 -0400 Subject: [Omaha.pm] Getopt::Long and opt_ variables In-Reply-To: <200505290115.26995.dthacker9@cox.net> References: <200505290115.26995.dthacker9@cox.net> Message-ID: <20050529131204.GA14218@jbisbee.com> * Dave Thacker (dthacker9 at cox.net) wrote: > my $opt_place; It works, just need our $opt_place; "my" restricts you to only set/access the value within the class, "our" lets you set/access the value outside of the class. Also, when it doubt, "use the source" perldoc -m Getopt::Long Thats what I did and just looked for "opt_" and found the following, so knew the code did as you explained... else { # Link to global $opt_XXX variable. # Make sure a valid perl identifier results. my $ov = $orig; $ov =~ s/\W/_/g; if ( $opctl{$name}[CTL_DEST] == CTL_DEST_ARRAY ) { print STDERR ("=> link \"$orig\" to \@$pkg","::opt_$ov\n") if $debug; eval ("\$linkage{\$orig} = \\\@".$pkg."::opt_$ov;"); } elsif ( $opctl{$name}[CTL_DEST] == CTL_DEST_HASH ) { print STDERR ("=> link \"$orig\" to \%$pkg","::opt_$ov\n") if $debug; eval ("\$linkage{\$orig} = \\\%".$pkg."::opt_$ov;"); } else { print STDERR ("=> link \"$orig\" to \$$pkg","::opt_$ov\n") if $debug; eval ("\$linkage{\$orig} = \\\$".$pkg."::opt_$ov;"); } } -- Jeff Bisbee / omaha-pm at jbisbee.com / jbisbee.com From omaha-pm at jbisbee.com Sun May 29 06:12:04 2005 From: omaha-pm at jbisbee.com (Jeff Bisbee) Date: Sun, 29 May 2005 09:12:04 -0400 Subject: [Omaha.pm] Getopt::Long and opt_ variables In-Reply-To: <200505290115.26995.dthacker9@cox.net> References: <200505290115.26995.dthacker9@cox.net> Message-ID: <20050529131204.GA14218@jbisbee.com> * Dave Thacker (dthacker9 at cox.net) wrote: > my $opt_place; It works, just need our $opt_place; "my" restricts you to only set/access the value within the class, "our" lets you set/access the value outside of the class. Also, when it doubt, "use the source" perldoc -m Getopt::Long Thats what I did and just looked for "opt_" and found the following, so knew the code did as you explained... else { # Link to global $opt_XXX variable. # Make sure a valid perl identifier results. my $ov = $orig; $ov =~ s/\W/_/g; if ( $opctl{$name}[CTL_DEST] == CTL_DEST_ARRAY ) { print STDERR ("=> link \"$orig\" to \@$pkg","::opt_$ov\n") if $debug; eval ("\$linkage{\$orig} = \\\@".$pkg."::opt_$ov;"); } elsif ( $opctl{$name}[CTL_DEST] == CTL_DEST_HASH ) { print STDERR ("=> link \"$orig\" to \%$pkg","::opt_$ov\n") if $debug; eval ("\$linkage{\$orig} = \\\%".$pkg."::opt_$ov;"); } else { print STDERR ("=> link \"$orig\" to \$$pkg","::opt_$ov\n") if $debug; eval ("\$linkage{\$orig} = \\\$".$pkg."::opt_$ov;"); } } -- Jeff Bisbee / omaha-pm at jbisbee.com / jbisbee.com From georgen at neillnet.com Sun May 29 20:34:12 2005 From: georgen at neillnet.com (georgen@neillnet.com) Date: Sun, 29 May 2005 22:34:12 -0500 (CDT) Subject: [Omaha.pm] Getopt::Long and opt_ variables In-Reply-To: <200505290115.26995.dthacker9@cox.net> References: <200505290115.26995.dthacker9@cox.net> Message-ID: <1643.192.168.10.11.1117424052.squirrel@192.168.10.11> Note that, if your code is running under the recommended use strict 'vars' pragma, it may be helpful to declare these package variables via use vars perhaps something like this: use vars qw/ $opt_size @opt_sizes $opt_bar /; so ... you just need to add, use vars qw/ $opt_place /; OR remove the statement, use strict; HTH, George. > In the second edition camel (on page 448), it says that" "If no linkage is > explicitly specified and no hash ref is passed, GetOptions() will put the > value of in a global variable named after the option preceded by opt_..." > Is this automagically done? This example doesn't seen to work . > > #!/usr/bin/perl -w > > use strict; > use Getopt::Long; > my $opt_place; > > &GetOptions("place=s"); > > print "Hello! $opt_place\n"; > > dthacker at fluffy:~/dev/dwofl/bin> ./test2.pl -place World Use of > uninitialized > value in concatenation (.) or string at ./test2.pl line 9. Hello! > > DT > > _______________________________________________ > Omaha-pm mailing list > Omaha-pm at pm.org > http://mail.pm.org/mailman/listinfo/omaha-pm > From omaha-pm at jbisbee.com Tue May 31 23:46:21 2005 From: omaha-pm at jbisbee.com (Jeff Bisbee) Date: Wed, 1 Jun 2005 02:46:21 -0400 Subject: [Omaha.pm] Getopt::Long and opt_ variables In-Reply-To: <1643.192.168.10.11.1117424052.squirrel@192.168.10.11> References: <200505290115.26995.dthacker9@cox.net> <1643.192.168.10.11.1117424052.squirrel@192.168.10.11> Message-ID: <20050601064621.GA28291@jbisbee.com> * georgen at neillnet.com (georgen at neillnet.com) wrote: > > Note that, if your code is running under the recommended use strict 'vars' > pragma, it may be helpful to declare these package variables via use vars > perhaps something like this: > > use vars qw/ $opt_size @opt_sizes $opt_bar /; > > > so ... you just need to add, > > use vars qw/ $opt_place /; > Just need to use 'our'. 'vars' is old skool for 'our' (well for variables in the current package anyway) (via "perldoc vars") NOTE: For variables in the current package, the functionality provided by this pragma has been superseded by "our" declarations, available in Perl v5.6.0 or later. See "our" in perlfunc. These do the same thing... use vars qw/ $opt_size @opt_sizes $opt_bar /; our ($opt_size, @opt_sizes, $opt_bar); > OR > > remove the statement, > > use strict; Darth Vader says, "Nooooooooooooooooo!!!" :P Also its almost generally a very bad idea to remove 'use strict;' Very bad things are bound to happen without you being the wiser :) -- Jeff Bisbee / omaha-pm at jbisbee.com / jbisbee.com