From scott.l.miller at hp.com Mon Aug 2 10:08:15 2004 From: scott.l.miller at hp.com (Miller, Scott L (Omaha Networks)) Date: Mon Aug 2 21:33:59 2004 Subject: [Omaha.pm] Date::Calc Message-ID: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E651@omaexc11.americas.cpqcorp.net> Yes, it's behaving correctly because 6/31, since there are only 30 days in June, becomes 7/1. So, yes you want the truncated version. BTW, I'm glad you're using Date::Calc, I looked at Date::Manip, which I think you wrote about a couple weeks ago. Although I'm impressed with the scope of Date::Manip, I particularly found the following lines from the documentation to be quite effective in making me look at other packages available: SHOULD I USE DATE::MANIP If you look in CPAN, you'll find that there are a number of Date and Time packages. Is Date::Manip the one you should be using? In my opinion, the answer is no most of the time. This sounds odd coming from the author of the software, but read on. I needed to be able to find the 2nd Wednesday of each month, Date::Calc was the package I settled on. -Scott -----Original Message----- From: omaha-pm-bounces@pm.org [mailto:omaha-pm-bounces@pm.org]On Behalf Of Jay Hannah Sent: Saturday, July 31, 2004 9:55 AM To: omaha-pm@pm.org Subject: [Omaha.pm] Date::Calc In the debugger after use Date::Calc qw( Today Add_Delta_YMD ); ----------- DB<3> x Today 0 2004 1 7 2 31 DB<4> x Add_Delta_YMD(Today, 0, -1, 0) 0 2004 1 7 2 1 ----------- That was not what I was expecting. I guess I was expecting 2004 6 30? j from perldoc Date::Calc --------------------------- o "($year,$month,$day) = Add_Delta_YMD($year,$month,$day, $Dy,$Dm,$Dd);" This function serves to add a years, months and days offset to a given date. (In order to add a weeks offset, simply multiply the weeks offset with ""7"" and add this number to your days offset.) Note that the three offsets for years, months and days are applied independently from each other. This also allows them to have different signs. The years and months offsets are applied first, and the days offset is applied last. If the resulting date happens to fall on a day after the end of the resulting month, like the 32nd of April or the 30th of February, then the date is simply counted forward into the next month (possibly also into the next year) by the number of excessive days (e.g., the 32nd of April will become the 2nd of May). BEWARE that this behaviour differs from that of previous versions of this module! In previous versions, the day was simply truncated to the maximum number of days in the resulting month. If you want the previous behaviour, use the new function ""Add_Delta_YM()"" (described immediately above) plus the function ""Add_Delta_Days()"" instead. BEWARE also that because a year and a month offset is not equivalent to a fixed number of days, the transfor- mation performed by this function is NOT ALWAYS REVERSIBLE! This is in contrast to the functions ""Add_Delta_Days()"" and ""Add_Delta_DHMS()"", which are fully and truly reversible (with the help of the func- tions ""Delta_Days()"" and ""Delta_DHMS()"", for instance). Note that for this same reason, @date = Add_Delta_YMD( Add_Delta_YMD(@date, $Dy,$Dm,$Dd), -$Dy,-$Dm,-$Dd); will in general NOT return the initial date ""@date"". Note that this is NOT a program bug but NECESSARILY so because of the variable lengths of years and months! ------------------ I guess I want Delta_YM instead? It's hard to report bugs when authors keep accurately documenting behaviors. -grin- j _______________________________________________ Omaha-pm mailing list Omaha-pm@pm.org http://www.pm.org/mailman/listinfo/omaha-pm From hjarce2001 at yahoo.com Tue Aug 3 03:45:26 2004 From: hjarce2001 at yahoo.com (Hugh Jarce) Date: Tue Aug 3 03:45:33 2004 Subject: [Omaha.pm] Date::Calc In-Reply-To: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E651@omaexc11.americas.cpqcorp.net> Message-ID: <20040803084526.92827.qmail@web90001.mail.scd.yahoo.com> "Miller, Scott L (Omaha Networks)" wrote: > If you look in CPAN, you'll find that there are a number of Date and > Time packages. Is Date::Manip the one you should be using? See also: http://datetime.perl.org/ http://www.perl.com/pub/a/2003/03/13/datetime.html Hugh __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail From jhannah at omnihotels.com Tue Aug 3 17:07:08 2004 From: jhannah at omnihotels.com (Jay Hannah) Date: Tue Aug 3 17:07:29 2004 Subject: [Omaha.pm] IO/Multiplex.pm warning Message-ID: <000501c479a6$38aab4a0$4722000a@omarests2> Hi Rob -- IO::Multiplex is awesome. I just thought you should know. -grin- I'm trying to get a rather complex project off the ground. One of the programs seems to be working fine, but is throwing this warning: ./com.pl IO::Multiplex read error: Bad file descriptor at /usr/lib/perl5/site_perl/5.8.3/IO/Multiplex.pm line 641, line 1. Th program in question does all kinds of silly things w/ IO::Multiplex. It - $mux->listen()'s on a local TCP port (IO::Socket::INET), allowing up to 100 connections - connects to a remote TCP port (IO::Socket::INET) and sends data there periodically - Launches (fork, exec) 6-20 children processes, and for each of those it - $mux->add($fh) a FIFO file that it needs to listen to - writes to a different FIFO $fh (So, IO::Multiplex is making my life much easier.) Anyhoo, here's the source throwing the warning (I added $0): circa line 641: unless (defined $rv) { next if $! == EINTR || $! == EAGAIN || $! == EWOULDBLOCK; # JAY added $0 warn "$0 IO::Multiplex read error: $!" if $! != ECONNRESET; } # There's an error, or we received EOF. If # there's pending data to be written, we leave # the connection open so it can be sent. If # the other end is closed for writing, the # send will error and we close down there. # Either way, we remove it from _readers as # we're no longer interested in reading from # it. The program seems to be working fine, do you think I should be concerned about that warning? Is it an indicator that I'm doing something sloppy somewhere and not cleaning up after myself properly? If so, is IO::Multiplex cleaning up after me anyway? Should I be very concerned? Not very? My other programs in the architecture use IO::Multiplex quite a bit too, and none of them throw that warning... -ponder- Thanks for your time, Jay Hannah Director of Development Omni Hotels Reservation Center Tel: (402) 952-6573 Mobile: (402) 578-3976 Email: jhannah@omnihotels.com Find out why we believe the Lone Star State is even more ideal this summer and about the Ideal Escape leisure package. Call 1-800-The-Omni or visit us at www.omnitexashotels.com. From omaha-pm at jbisbee.com Tue Aug 3 19:33:29 2004 From: omaha-pm at jbisbee.com (Jeff Bisbee) Date: Tue Aug 3 19:33:26 2004 Subject: [Omaha.pm] IO/Multiplex.pm warning In-Reply-To: <000501c479a6$38aab4a0$4722000a@omarests2> References: <000501c479a6$38aab4a0$4722000a@omarests2> Message-ID: <20040804003329.GA7215@jbisbee.com> * Jay Hannah (jhannah@omnihotels.com) wrote: > IO::Multiplex is awesome. I just thought you should know. -grin- POE is also another way to multiplex sockets and do a whole heck of a lot more. One quick way to start playing with POE is to try out some of the cookbook examples at: http://poe.perl.org/?POE_Cookbook/Job_Server http://poe.perl.org/?POE_Cookbook/Application_Servers_2 http://poe.perl.org/?POE_Cookbook/Application_Servers Also checkout the other cookbook examples: http://poe.perl.org/?POE_Cookbook -- Jeff Bisbee / omaha-pm@jbisbee.com / jbisbee.com From jhannah at omnihotels.com Wed Aug 4 11:09:25 2004 From: jhannah at omnihotels.com (Jay Hannah) Date: Wed Aug 4 11:10:28 2004 Subject: [Omaha.pm] IO/Multiplex.pm warning In-Reply-To: <20040804003329.GA7215@jbisbee.com> Message-ID: <001801c47a3d$69fb7f20$4722000a@omarests2> > POE is also another way to multiplex sockets and do a whole heck of a > lot more. In terms of pure multitasking capacity and maintenance... (Process 100 simultaneous inbound requests) Is POE typically used on top of Apache/mod_perl? Instead of Apache/mod_perl? j From omaha-pm at jbisbee.com Wed Aug 4 12:17:47 2004 From: omaha-pm at jbisbee.com (Jeff Bisbee) Date: Wed Aug 4 12:17:42 2004 Subject: [Omaha.pm] IO/Multiplex.pm warning In-Reply-To: <001801c47a3d$69fb7f20$4722000a@omarests2> References: <20040804003329.GA7215@jbisbee.com> <001801c47a3d$69fb7f20$4722000a@omarests2> Message-ID: <20040804171747.GC21599@jbisbee.com> * Jay Hannah (jhannah@omnihotels.com) wrote: > In terms of pure multitasking capacity and maintenance... > (Process 100 simultaneous inbound requests) > Is POE typically used on top of Apache/mod_perl? Instead of Apache/mod_perl? Neither, POE is basically a perl kernel centered around slicing execution into tiny bits so they don't block. (at its core its an event loop with hires time stamps so you can schedule events to execute in the future) I haven't done anything hardcore, but I asked on #poe on irc.perl.org and got this answer... anybody know any limits os POE handle socket connections? someone on a perl monger mailing list mentioned IO::Multiplex and I suggested POE as an alternative I've never pushed any limits, his current implementation handles 100 simultaneous connections eh... on short order tests I've pushed 1000 easily, but it all depends on what you're doing I would just suggest playing with it. It's EXTREMELY well tested and just takes a bit to wrap your head around it. You might want to sign up to the mailing list, or hop on irc.perl.org, #poe if you have questions. -- Jeff Bisbee / omaha-pm@jbisbee.com / jbisbee.com From jay at jays.net Wed Aug 4 20:14:20 2004 From: jay at jays.net (Jay Hannah) Date: Wed Aug 4 20:14:05 2004 Subject: [Omaha.pm] Date::Calc In-Reply-To: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E651@omaexc11.americas.cpqcorp.net> References: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E651@omaexc11.americas.cpqcorp.net> Message-ID: On Aug 2, 2004, at 10:08 AM, Miller, Scott L (Omaha Networks) wrote: > I looked at Date::Manip, which I think you wrote about a couple weeks > ago. That must have been my evil twin. I/we've been using Date::Calc exclusively for as long as I can remember @ my current job (5 yrs now). I, too, hope to someday submit something to CPAN and recommend everyone not use it. Gotta have dreams, baby! -grin- j From jay at jays.net Wed Aug 4 20:19:25 2004 From: jay at jays.net (Jay Hannah) Date: Wed Aug 4 20:19:14 2004 Subject: [Omaha.pm] IO/Multiplex.pm warning In-Reply-To: <20040804171747.GC21599@jbisbee.com> References: <20040804003329.GA7215@jbisbee.com> <001801c47a3d$69fb7f20$4722000a@omarests2> <20040804171747.GC21599@jbisbee.com> Message-ID: <7D266AD2-E67D-11D8-BA7A-000A95E317B8@jays.net> On Aug 4, 2004, at 12:17 PM, Jeff Bisbee wrote: > * Jay Hannah (jhannah@omnihotels.com) wrote: >> In terms of pure multitasking capacity and maintenance... >> (Process 100 simultaneous inbound requests) >> Is POE typically used on top of Apache/mod_perl? Instead of >> Apache/mod_perl? > > Neither, POE is basically a perl kernel centered around slicing > execution > into tiny bits so they don't block. (at its core its an event loop with > hires time stamps so you can schedule events to execute in the future) -ponder- For some reason I had the idea stuck in my noggin that POE was an OO Perl application server in a box. Since my only concrete application server experience is with Apache/mod_perl, I was curious about that relationship... I understand you use a lot of POE @ work. I figured that was (at least partially) to support the web sites you run? Are you using Apache? Or do the POE boxes live elsewhere in your enterprise? j From omaha-pm at jbisbee.com Wed Aug 4 21:03:26 2004 From: omaha-pm at jbisbee.com (Jeff Bisbee) Date: Wed Aug 4 21:03:17 2004 Subject: [Omaha.pm] IO/Multiplex.pm warning In-Reply-To: <7D266AD2-E67D-11D8-BA7A-000A95E317B8@jays.net> References: <20040804003329.GA7215@jbisbee.com> <001801c47a3d$69fb7f20$4722000a@omarests2> <20040804171747.GC21599@jbisbee.com> <7D266AD2-E67D-11D8-BA7A-000A95E317B8@jays.net> Message-ID: <20040805020326.GA30985@jbisbee.com> * Jay Hannah (jay@jays.net) wrote: > I understand you use a lot of POE @ work. Nope, no POE at work, just for fun :) (at CBS Sportsline we use apache/mod_perl). Rocco Caputo, a member of SouthFlorida.pm, originally designed POE to be a framework to run a MUD. The core of the project turned into POE (Perl Object Environment), but its really away to do some very complex stuff with minimal effort. The big hit is just testing out some of the sample scripts and wrapping your head around it. -- Jeff Bisbee / omaha-pm@jbisbee.com / jbisbee.com From jay at jays.net Thu Aug 5 01:27:44 2004 From: jay at jays.net (Jay Hannah) Date: Thu Aug 5 01:27:31 2004 Subject: [Omaha.pm] Meetings! 3rd Thr of every month! In-Reply-To: <9A8B75E3985324438F1BFA08B160E820215068@suxsvr.willconsult.com> References: <9A8B75E3985324438F1BFA08B160E820215068@suxsvr.willconsult.com> Message-ID: <8F77DC0C-E6A8-11D8-BA7A-000A95E317B8@jays.net> Ok, let's try this for a change... I hereby declare Omaha Perl Monger meetings will be held the 3rd Thursday of every month hereafter. (With a nod to perl.meetup.com.) See top of our homepage for directions, etc.: http://omaha.pm.org/ Check out the auto-date source code. Date::Calc is good stuff. Yes, I am too lazy to look at a calendar every month and update a web site. That's what Palm Pilots and Perl are for. -grin- Let's follow up on Scott's lengthy IP sorting email* @ the meeting. Here's my proposal: IP Sorting Lab: Benchmark different approaches -- fastest sort wins the grand prize** Components: - Write a program to generate random IPv4 addresses. Bonus points for IPv6. - Benchmark 10,000+ IPs sorting through Jay's kooky little ip_sort, posted in July. Use the Perl Profiler if we get really kooky. - Benchmark 10,000+ IPs converted to a sortable format first, then run through regular sort(). - Perl miscellania. (IO::Multiplex, IO::Socket::INET anyone? That's been my life lately.) - Adjourn and drink beer somewhere. * http://mail.pm.org/archives/omaha-pm/2004-July/000041.html ** deep satisfaction at a jorb*** well done *** homestarrunner.com reference On Jul 22, 2004, at 11:30 AM, Ryan Stille wrote: > Was there a meeting last week? I was wondering when the next Perl > meeting was going to me, it seems like's been about a month? So I > checked the website and it says there was a meeting last week! Are > meeting notices not posted to the list? They are for the Omaha LUG > and the Sioux City LUG. I find them very helpful. Ya, I put that date on the website a week before that date, but never got around to formulating an agenda and emailing it out. I was there, just in case anyone showed up, working w/ Jay Swackhamer on a project for the day job. It was my own little secret meeting w/ myself. -grin- Hopefully this new system will work out peachily for everyone. I'll try to remember to send out reminders a week before each mtg. Cya soon, j From jay at jays.net Thu Aug 5 01:49:13 2004 From: jay at jays.net (Jay Hannah) Date: Thu Aug 5 01:49:04 2004 Subject: [Omaha.pm] simple syntax question In-Reply-To: <20040729023657.56491.qmail@web90006.mail.scd.yahoo.com> References: <20040729023657.56491.qmail@web90006.mail.scd.yahoo.com> Message-ID: <8FAFAE3B-E6AB-11D8-BA7A-000A95E317B8@jays.net> On Jul 28, 2004, at 9:36 PM, Hugh Jarce wrote: > Ryan Stille wrote: >> $tmp1 = $FORM->param('respond_email'); >> $tmp2 = $FORM->param('name'); >> $tmp1 =~ s/\n|\r//g; >> $tmp2 =~ s/\n|\r//g; >> $FORM->param(-name=>'respond_email',-value=>$tmp1); >> $FORM->param(-name=>'name', -value=>$tmp2); > > I suppose you could hide the temporary in a function like this: > > sub remove_newlines { > my $t = shift; > $t =~ tr/\r\n//d; > return $t; > } > > allowing you to write code like this (untested): > > $FORM->param(-name => 'name', > -value => remove_newlines( $FORM->param('name') ) ); Or even something like foreach ($FORM->param) { my $t = $FORM->param($_); $t =~ tr/\r\n//d; $FORM->param($_, $t); } j From jay at jays.net Thu Aug 5 02:22:17 2004 From: jay at jays.net (Jay Hannah) Date: Thu Aug 5 02:22:03 2004 Subject: [Omaha.pm] Sort quickie In-Reply-To: <20040715033204.71348.qmail@web90005.mail.scd.yahoo.com> References: <20040715033204.71348.qmail@web90005.mail.scd.yahoo.com> Message-ID: <2E2D7CD4-E6B0-11D8-BA7A-000A95E317B8@jays.net> On Jul 14, 2004, at 10:32 PM, Hugh Jarce wrote: > This sub can be written more efficiently as: > ? sub by_date2 { substr($a,4) cmp substr($b,4) || $a cmp $b } > or: > ? sub by_date3 { substr($a,4).$a cmp substr($b,4).$b } Wow. Very slick. > Out of curiosity, I benchmarked 4 different ways to do it: > ? > use strict; > use Benchmark; -ponder- I need to study Benchmark. Looks cool. What's the point of @x? Can sub j9 { my @x = sort by_date @dates } be written as sub j9 { sort by_date @dates } ? > sub j1 { > ??? my @x = map { substr($_,4) } sort map { substr($_,4).$_ } @dates > } -laugh- Took me 3 minutes to figure out what that does. map tends to confuse my limited synapses. > Which surprised me. I expected j1 to be much faster. Usually its faster for me to re-write a use of map than it is for me to figure out what I was doing when I wrote it. -grin- Typically I can't grok map at a glance, which slows me down. Can't argue w/ fast benchmarking though! Thanks for the tips! j From hjarce2001 at yahoo.com Thu Aug 5 18:21:41 2004 From: hjarce2001 at yahoo.com (Hugh Jarce) Date: Thu Aug 5 18:21:43 2004 Subject: [Omaha.pm] Sort quickie In-Reply-To: <2E2D7CD4-E6B0-11D8-BA7A-000A95E317B8@jays.net> Message-ID: <20040805232141.17367.qmail@web90002.mail.scd.yahoo.com> Jay Hannah : > -ponder- I need to study Benchmark. Looks cool. What's the point of > @x? Can > > sub j9 { my @x = sort by_date @dates } > > be written as > > sub j9 { sort by_date @dates } > ? No. Benchmark calls the subs in scalar context; the my @x is used to force sort to be called in list context. As for what sort *should* do in scalar context, noone is really sure -- the latest consensus is that it should play nethack: >> sub j1 { >>     my @x = map { substr($_,4) } sort map { substr($_,4).$_ } @dates >> } > > -laugh- Took me 3 minutes to figure out what that does. map tends to > confuse my limited synapses. > >> Which surprised me. I expected j1 to be much faster. > > Usually its faster for me to re-write a use of map than it is for me to > figure out what I was doing when I wrote it. -grin- Typically I can't > grok map at a glance, which slows me down. Can't argue w/ fast > benchmarking though! > > Thanks for the tips! You're welcome. Actually, I wasn't trying to be silly on purpoose (for once), just following the standard GRT sort hack: The GRT and its cousin the Schwartzian Transform are usually a lot faster whenever the comparison function is expensive because they pre-compute the sort keys just n times (rather than n log n when called by sort). The GRT is usually faster than the Schwartzian Transform because sort without a sort block or function is done in C and so is faster than interpreting the Perl sort function. Hugh __________________________________ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo From hjarce2001 at yahoo.com Thu Aug 5 18:21:41 2004 From: hjarce2001 at yahoo.com (Hugh Jarce) Date: Thu Aug 5 18:21:49 2004 Subject: [Omaha.pm] Sort quickie In-Reply-To: <2E2D7CD4-E6B0-11D8-BA7A-000A95E317B8@jays.net> Message-ID: <20040805232141.17367.qmail@web90002.mail.scd.yahoo.com> Jay Hannah : > -ponder- I need to study Benchmark. Looks cool. What's the point of > @x? Can > > sub j9 { my @x = sort by_date @dates } > > be written as > > sub j9 { sort by_date @dates } > ? No. Benchmark calls the subs in scalar context; the my @x is used to force sort to be called in list context. As for what sort *should* do in scalar context, noone is really sure -- the latest consensus is that it should play nethack: >> sub j1 { >>     my @x = map { substr($_,4) } sort map { substr($_,4).$_ } @dates >> } > > -laugh- Took me 3 minutes to figure out what that does. map tends to > confuse my limited synapses. > >> Which surprised me. I expected j1 to be much faster. > > Usually its faster for me to re-write a use of map than it is for me to > figure out what I was doing when I wrote it. -grin- Typically I can't > grok map at a glance, which slows me down. Can't argue w/ fast > benchmarking though! > > Thanks for the tips! You're welcome. Actually, I wasn't trying to be silly on purpoose (for once), just following the standard GRT sort hack: The GRT and its cousin the Schwartzian Transform are usually a lot faster whenever the comparison function is expensive because they pre-compute the sort keys just n times (rather than n log n when called by sort). The GRT is usually faster than the Schwartzian Transform because sort without a sort block or function is done in C and so is faster than interpreting the Perl sort function. Hugh __________________________________ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo From rps at willconsult.com Fri Aug 6 07:56:34 2004 From: rps at willconsult.com (Ryan Stille) Date: Fri Aug 6 07:56:37 2004 Subject: [Omaha.pm] Meetings! 3rd Thr of every month! Message-ID: <9A8B75E3985324438F1BFA08B160E820215089@suxsvr.willconsult.com> Jay Hannah wrote: > Ok, let's try this for a change... > > I hereby declare Omaha Perl Monger meetings will be held the 3rd > Thursday of every month hereafter. (With a nod to perl.meetup.com.) FYI, the third Thursday is when the Omaha Macromedia (formerly ColdFusion) group meets. Although they haven't been meeting for a while, but they are supposed to start up again soon (this month I think). -Ryan From scott.l.miller at hp.com Fri Aug 6 12:20:23 2004 From: scott.l.miller at hp.com (Miller, Scott L (Omaha Networks)) Date: Fri Aug 6 12:20:40 2004 Subject: [Omaha.pm] Sort quickie Message-ID: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E65A@omaexc11.americas.cpqcorp.net> Very cool! This thread has taught me about the map function. I'd pretty much either ignored or glossed over ever reading about them before. And as a bonus, I found out about the ST, GRT topics! mmm, mmm, good... Thanks! -Scott -----Original Message----- From: omaha-pm-bounces@mail.pm.org [mailto:omaha-pm-bounces@mail.pm.org]On Behalf Of Hugh Jarce Sent: Thursday, August 05, 2004 6:22 PM To: Perl Mongers of Omaha, Nebraska USA; Perl Mongers of Omaha, Nebraska USA Subject: Re: [Omaha.pm] Sort quickie Jay Hannah : > -ponder- I need to study Benchmark. Looks cool. What's the point of > @x? Can > > sub j9 { my @x = sort by_date @dates } > > be written as > > sub j9 { sort by_date @dates } > ? No. Benchmark calls the subs in scalar context; the my @x is used to force sort to be called in list context. As for what sort *should* do in scalar context, noone is really sure -- the latest consensus is that it should play nethack: >> sub j1 { >> ??? my @x = map { substr($_,4) } sort map { substr($_,4).$_ } @dates >> } > > -laugh- Took me 3 minutes to figure out what that does. map tends to > confuse my limited synapses. > >> Which surprised me. I expected j1 to be much faster. > > Usually its faster for me to re-write a use of map than it is for me to > figure out what I was doing when I wrote it. -grin- Typically I can't > grok map at a glance, which slows me down. Can't argue w/ fast > benchmarking though! > > Thanks for the tips! You're welcome. Actually, I wasn't trying to be silly on purpoose (for once), just following the standard GRT sort hack: The GRT and its cousin the Schwartzian Transform are usually a lot faster whenever the comparison function is expensive because they pre-compute the sort keys just n times (rather than n log n when called by sort). The GRT is usually faster than the Schwartzian Transform because sort without a sort block or function is done in C and so is faster than interpreting the Perl sort function. Hugh __________________________________ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo _______________________________________________ Omaha-pm mailing list Omaha-pm@mail.pm.org http://www.pm.org/mailman/listinfo/omaha-pm From td3201 at gmail.com Fri Aug 6 23:57:07 2004 From: td3201 at gmail.com (Terry) Date: Fri Aug 6 23:57:20 2004 Subject: [Omaha.pm] Sort quickie In-Reply-To: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E65A@omaexc11.americas.cpqcorp.net> References: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E65A@omaexc11.americas.cpqcorp.net> Message-ID: <8ee0610104080621572449ff91@mail.gmail.com> This thread reminded me of how little I know of perl.....I just pretend more or less...... On Fri, 6 Aug 2004 12:20:23 -0500, Miller, Scott L (Omaha Networks) wrote: > Very cool! This thread has taught me about the map function. I'd pretty much either ignored or glossed over ever reading about them before. > > And as a bonus, I found out about the ST, GRT topics! mmm, mmm, good... > > Thanks! > > -Scott > > > > -----Original Message----- > From: omaha-pm-bounces@mail.pm.org > [mailto:omaha-pm-bounces@mail.pm.org]On Behalf Of Hugh Jarce > Sent: Thursday, August 05, 2004 6:22 PM > To: Perl Mongers of Omaha, Nebraska USA; Perl Mongers of Omaha, Nebraska > USA > Subject: Re: [Omaha.pm] Sort quickie > > Jay Hannah : > > -ponder- I need to study Benchmark. Looks cool. What's the point of > > @x? Can > > > > sub j9 { my @x = sort by_date @dates } > > > > be written as > > > > sub j9 { sort by_date @dates } > > ? > > No. Benchmark calls the subs in scalar context; the my @x is used to > force sort to be called in list context. As for what sort *should* > do in scalar context, noone is really sure -- the latest consensus > is that it should play nethack: > > > > > >> sub j1 { > >> my @x = map { substr($_,4) } sort map { substr($_,4).$_ } @dates > >> } > > > > -laugh- Took me 3 minutes to figure out what that does. map tends to > > confuse my limited synapses. > > > >> Which surprised me. I expected j1 to be much faster. > > > > Usually its faster for me to re-write a use of map than it is for me to > > figure out what I was doing when I wrote it. -grin- Typically I can't > > grok map at a glance, which slows me down. Can't argue w/ fast > > benchmarking though! > > > > Thanks for the tips! > > You're welcome. Actually, I wasn't trying to be silly on purpoose > (for once), just following the standard GRT sort hack: > > > > The GRT and its cousin the Schwartzian Transform are usually a lot > faster whenever the comparison function is expensive because they > pre-compute the sort keys just n times (rather than n log n when > called by sort). The GRT is usually faster than the Schwartzian > Transform because sort without a sort block or function is done > in C and so is faster than interpreting the Perl sort function. > > Hugh > > __________________________________ > Do you Yahoo!? > Take Yahoo! Mail with you! Get it on your mobile phone. > http://mobile.yahoo.com/maildemo > _______________________________________________ > Omaha-pm mailing list > Omaha-pm@mail.pm.org > http://www.pm.org/mailman/listinfo/omaha-pm > > _______________________________________________ > Omaha-pm mailing list > Omaha-pm@mail.pm.org > http://www.pm.org/mailman/listinfo/omaha-pm > From IrishMASMS at olug.org Sat Aug 7 22:15:36 2004 From: IrishMASMS at olug.org (OBrien, Timothy (Omaha Linux Users Group - OLUG)) Date: Sat Aug 7 22:15:35 2004 Subject: [Omaha.pm] Meetings! 3rd Thr of every month! In-Reply-To: <9A8B75E3985324438F1BFA08B160E820215089@suxsvr.willconsult.com> References: <9A8B75E3985324438F1BFA08B160E820215089@suxsvr.willconsult.com> Message-ID: <3640.68.229.175.143.1091934936.squirrel@admin.olug.org> > Jay Hannah wrote: >> Ok, let's try this for a change... >> >> I hereby declare Omaha Perl Monger meetings will be held the 3rd >> Thursday of every month hereafter. (With a nod to perl.meetup.com.) > > FYI, the third Thursday is when the Omaha Macromedia (formerly ColdFusion) > group meets. Although they haven't been meeting for a while, but they are > supposed to start up again soon (this month I think). > > -Ryan Dang, there are so many different groups in the Omaha area, how are we supposed to jeep track of them all??? Not even including the meetup.com stuff..... Someone really should set up ITOmaha.com/org/net or OmahaIT.com/org/net with a calendar of events..... -- Timothy "Irish" O'Brien Publicity & Social activities chairperson Omaha Linux User's Group (OLUG) ---------------------------------------------- A: No. Q: Should I include e-mail quotations after my reply? ===================================================== An often repeated quote on news.admin.net-abuse.email: "Spam is not about content, it is about consent". -------------------------------- Microsoft: Where do you want to go today? Linux: Where do you want to go tomorrow? FreeBSD: Are you guys coming or what? From dan at linder.org Thu Aug 12 10:12:28 2004 From: dan at linder.org (Daniel Linder) Date: Thu Aug 12 10:09:48 2004 Subject: [Omaha.pm] AI-type string comparisons using Perl... Message-ID: <37155.12.160.138.57.1092323548.squirrel@12.160.138.57> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello everyone! I am working on a small script that will compare some text output from a program and parse out the numbers I want to act upon. Unfortunatly the output from the script is quite "humanized" and really ugly to parse using RegExp. Does anyone know of a perl module/function that can take a template string and use that to extract the values into variables for further use? Here is how I am starting to work on this: 1 @OUTPUT = `/path/to/ovstatus`; 2 #--begin output--- 3 # object manager name: netmon 4 #...snip... 5 # 14:30:00 Polling 0 interfaces, 0 polls/hour. 0 overdue polls, current maximum 0 [...etc...] average 0.2 msec/lookup. 6 #--end output--- 7 ($LINE) = grep /overdue.polls/i, @OUTPUT; 8 $RAWRATE =~ /Polling.*, (\d*) ([^\s]*)\. /i; 9 $RATE = $1; 10 $RATEUNITS = $2; ...and so on... Line 7 finds the single line that I want to work with and puts that into $LINE. I have to repeat lines 8-10 for all the values I want to pull out of that line. I started with a single large regexp that was a nightmare to debug if I got off in my RegExp syntax. :( Anyone got other ideas? I will be using this method for many other programs on the system I want to monitor so the more flexible the parsing routine the better. Dan - - - - - "I do not fear computer, I fear the lack of them." -- Isaac Asimov -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBG4jcNiBNyqUzGb8RAlE9AJwO6dFCgsPy4lfIhYvAtER2DcI/SACZAf5R RU8GrLUCrHhchmF53ASntm0= =EJd3 -----END PGP SIGNATURE----- From scott.l.miller at hp.com Thu Aug 12 17:57:39 2004 From: scott.l.miller at hp.com (Miller, Scott L (Omaha Networks)) Date: Thu Aug 12 17:57:43 2004 Subject: [Omaha.pm] AI-type string comparisons using Perl... Message-ID: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E668@omaexc11.americas.cpqcorp.net> You think that's ugly? Try parsing through a syslog file that has various Cisco routers, Cisco Catalyst switches, Nortel BN routers, Nortel Passport switches, foundry gear, and old Centillion (now Nortel) switches all reporting into the same file. And then you want to try to identify the "important" events... The best solution I've created is to first split each and every line into a generic array, then depending on what exactly you were looking in any particular case, you've got both the original line still stored in $_, and the various fields broken by spaces. So, for instance, here is a bit of sample code from that code I described above... sub GuessBoxType { #We've got the whole line in $_, that line split by spaces in @a #the IP address (better have anyway), and maybe a name... #A "message repeated" message doesn't give enough info to guess... if ( /last message repeated/ ) { #ignore return ""; } elsif ( /previous event / ) { #ignore return ""; } if ( /ENTITY\/EVENT CODE:/ ) { #Nortel RS router #nortel BN router log msgs include the string "ENTITY/EVENT CODE:" return "nortel-rtr"; } if ( /[0-9]+\/[0-9]+ [0-9]+ [\w\-]+:/ ) { #Cisco CSS #matching on the "slot/port msg# subSystemName-level:" portion of logmsg return "cisco-css"; } if ( $a[4] =~ /^CPU[0-9]+$/ ) { #Passport 8600 switch #Each message includes which CPU is reporting the issue. return "passport-8600"; } if ( substr($a[4],-1,1) eq ',' ) { #Foundry Server Iron #Each message starts with the "boxname" as known by the serveriron itself #followed by a comma ','. return "foundry-svrirn"; } if ( /\[[0-9]+ ([0-9]{2}:){3}[0-9]{3}\]/ ) { #Excellar #matching on "[msg# hour:min:sec:msec]" portion of log message return "accelar"; } ... So, depending on what device I'm attempting to identify, I'll use either a straight regex, or some portions of the generic array @a, which is created with the following line near the top of my while(<>) loop: @a=split(/\s+/); (The above isn't usable out of the box, BTW, @a is modified some before 'Guess_box_type' gets called...) Although I'm not entirely clear what you're trying to do, my gut reaction is that you don't want to grep for various things and then later try to put it all together. If at all possible, just process the file one line at a time. If you'd like to provide more information about what you're trying to do, I, and probably others, would be happy to help find the best way to accomplish the task. -Scott PS. If anyone is actually interested in my syslog processing code, I'd be happy to oblige... -----Original Message----- From: omaha-pm-bounces@mail.pm.org [mailto:omaha-pm-bounces@mail.pm.org]On Behalf Of Daniel Linder Sent: Thursday, August 12, 2004 10:12 AM To: omaha-pm@mail.pm.org Subject: [Omaha.pm] AI-type string comparisons using Perl... -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello everyone! I am working on a small script that will compare some text output from a program and parse out the numbers I want to act upon. Unfortunatly the output from the script is quite "humanized" and really ugly to parse using RegExp. Does anyone know of a perl module/function that can take a template string and use that to extract the values into variables for further use? Here is how I am starting to work on this: 1 @OUTPUT = `/path/to/ovstatus`; 2 #--begin output--- 3 # object manager name: netmon 4 #...snip... 5 # 14:30:00 Polling 0 interfaces, 0 polls/hour. 0 overdue polls, current maximum 0 [...etc...] average 0.2 msec/lookup. 6 #--end output--- 7 ($LINE) = grep /overdue.polls/i, @OUTPUT; 8 $RAWRATE =~ /Polling.*, (\d*) ([^\s]*)\. /i; 9 $RATE = $1; 10 $RATEUNITS = $2; ...and so on... Line 7 finds the single line that I want to work with and puts that into $LINE. I have to repeat lines 8-10 for all the values I want to pull out of that line. I started with a single large regexp that was a nightmare to debug if I got off in my RegExp syntax. :( Anyone got other ideas? I will be using this method for many other programs on the system I want to monitor so the more flexible the parsing routine the better. Dan - - - - - "I do not fear computer, I fear the lack of them." -- Isaac Asimov -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBG4jcNiBNyqUzGb8RAlE9AJwO6dFCgsPy4lfIhYvAtER2DcI/SACZAf5R RU8GrLUCrHhchmF53ASntm0= =EJd3 -----END PGP SIGNATURE----- _______________________________________________ Omaha-pm mailing list Omaha-pm@mail.pm.org http://www.pm.org/mailman/listinfo/omaha-pm From jay at jays.net Mon Aug 16 22:28:50 2004 From: jay at jays.net (Jay Hannah) Date: Mon Aug 16 22:28:36 2004 Subject: [Omaha.pm] Meeting this Thr! In-Reply-To: <8F77DC0C-E6A8-11D8-BA7A-000A95E317B8@jays.net> References: <9A8B75E3985324438F1BFA08B160E820215068@suxsvr.willconsult.com> <8F77DC0C-E6A8-11D8-BA7A-000A95E317B8@jays.net> Message-ID: <8E7E6574-EFFD-11D8-A3A7-000A95E317B8@jays.net> Just a reminder: Next mtg is this Thursday. j On Aug 5, 2004, at 1:27 AM, Jay Hannah wrote: > > Ok, let's try this for a change... > > I hereby declare Omaha Perl Monger meetings will be held the 3rd > Thursday of every month hereafter. (With a nod to perl.meetup.com.) > > See top of our homepage for directions, etc.: > > http://omaha.pm.org/ > > Check out the auto-date source code. Date::Calc is good stuff. Yes, I > am too lazy to look at a calendar every month and update a web site. > That's what Palm Pilots and Perl are for. -grin- > > Let's follow up on Scott's lengthy IP sorting email* @ the meeting. > Here's my proposal: > > IP Sorting Lab: Benchmark different approaches -- fastest sort wins > the grand prize** > > Components: > - Write a program to generate random IPv4 addresses. Bonus points for > IPv6. > - Benchmark 10,000+ IPs sorting through Jay's kooky little ip_sort, > posted in July. Use the Perl Profiler if we get really kooky. > - Benchmark 10,000+ IPs converted to a sortable format first, then run > through regular sort(). > - Perl miscellania. (IO::Multiplex, IO::Socket::INET anyone? That's > been my life lately.) > - Adjourn and drink beer somewhere. > > * http://mail.pm.org/archives/omaha-pm/2004-July/000041.html > ** deep satisfaction at a jorb*** well done > *** homestarrunner.com reference > > On Jul 22, 2004, at 11:30 AM, Ryan Stille wrote: >> Was there a meeting last week? I was wondering when the next Perl >> meeting was going to me, it seems like's been about a month? So I >> checked the website and it says there was a meeting last week! Are >> meeting notices not posted to the list? They are for the Omaha LUG >> and the Sioux City LUG. I find them very helpful. > > Ya, I put that date on the website a week before that date, but never > got around to formulating an agenda and emailing it out. I was there, > just in case anyone showed up, working w/ Jay Swackhamer on a project > for the day job. It was my own little secret meeting w/ myself. -grin- > > Hopefully this new system will work out peachily for everyone. I'll > try to remember to send out reminders a week before each mtg. > > Cya soon, > > j From dan at linder.org Tue Aug 17 15:49:28 2004 From: dan at linder.org (Daniel Linder) Date: Tue Aug 17 15:46:14 2004 Subject: [Omaha.pm] [OT]For Sale: two 512MB ECC DDR PC2100 Message-ID: <48275.12.160.138.50.1092775768.squirrel@12.160.138.50> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Everyone, I picked up two sticks of RAM (each 512MB, DDR, PC2100, CL2.5, _ECC_) a few months ago planning on putting them into a new PC/server at home. Unfortunately, ECC RAM doesn?t work in any of my existing home systems and I didn?t expect the price of an ECC-capable motherboard to be a premium price over non-ECC MBs... :( So, I?d like to sell these to someone who can use them. They are HP/Compaq brand (Samsung chips), PC2100 DDR 266 CL2.5 Registered. I?ll either sell them for $75 each or work out a trade with someone if they have two 512MB non-ECC DDR sticks they would like to part with. Dan - - - - - "I do not fear computer, I fear the lack of them." -- Isaac Asimov -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBIm9YNiBNyqUzGb8RAh4GAJ9JFIxe/AzHdPsHPNjgv1RUnI9GHACePRjd /zUzN7H79foeBkb2fa8m5Ck= =UrrM -----END PGP SIGNATURE----- From jhannah at omnihotels.com Wed Aug 18 15:38:29 2004 From: jhannah at omnihotels.com (Jay Hannah) Date: Wed Aug 18 15:38:39 2004 Subject: [Omaha.pm] RE: Model::Common and Model::DataTypes perldoc added In-Reply-To: <200408181018.i7IAIHsU018723@mail-omaha.omnihotels.com> Message-ID: <005001c48563$52b9a090$4722000a@omarests2> In vi ":set list" of your POD shows this: $ =head2 is_iata_num$ $ This method validates a provided iata number using our $ Model::omares::Prod::omtamst table$ $ Usage: $self->is_iata_num("12345678");$ $ =cut $ sub is_iata_num {$ This is bad mojo. 1) Regular sentences in POD should not be indented with spaces. 2+ space indention in POD is special. It indicates that the text cannot line wrap (e.g.: source code). Non-indented text is handly in POD as POD intepreters will auto re-wrap short and long lines automatically, just like web browsers wrap HTML. Additionally, in HTMLified POD non-indented text is printed in (normal) variable width font and indented text is displayed in fixed width font. So indention of your short Usage: example is cool, but the sentence describing what it does should not be indented. 2) The line immediately after the =head2 line contains a space. That's bad. That indicates that the =head2 is not over yet. So, in HTMLified POD, the entire description ends up wrapped in

tags, which is ugly. So, the block above should look like this instead: $ =head2 is_iata_num$ $ This method validates a provided iata number using our $ Model::omares::Prod::omtamst table$ $ Usage: $self->is_iata_num("12345678");$ $ =cut $ sub is_iata_num {$ which is pretty in HTML. I committed the changes. They're all pretty now. -grin- http://razorbill/~jhannah/MVC/Model/Common.html http://razorbill/~jhannah/MVC/Model/DataTypes.html j -----Original Message----- From: Sean Baker [mailto:pbaker@omnihotels.com] Sent: Wednesday, August 18, 2004 5:18 AM To: jhannah@omnihotels.com Subject: RE: Model::Common and Model::DataTypes perldoc added I'm using =head2 method_name =cut Wrong? Sean Baker Software Architect Omni Hotels (402) 952-6508 pbaker@omnihotels.com Find out why we believe the Lone Star State is even more ideal this summer and about the Ideal Escape leisure package. Call 1-800-The-Omni or visit us at www.omnitexashotels.com ------------------------------------------------------------------------------ From: Jay Hannah [mailto:jhannah@omnihotels.com] Sent: Tuesday, August 17, 2004 3:06 PM To: pbaker@omnihotels.com Subject: RE: Model::Common and Model::DataTypes perldoc added Weird glitches in how you're doing POD? http://razorbill/~jhannah/MVC/Model/Common.html http://razorbill/~jhannah/MVC/Model/DataTypes.html j -----Original Message----- From: Sean Baker [mailto:pbaker@omnihotels.com] Sent: Monday, July 26, 2004 9:40 AM To: resmis@omnihotels.com Subject: Model::Common and Model::DataTypes perldoc added I've added perldoc to our two most important Core Model classes, Common and DataTypes. You can read it by going to Omni::MVC::Model and typing "perldoc Common" or "perldoc DataTypes". http://cvs/source/MVC/Model/Common.pm http://cvs/source/MVC/Model/DataTypes.pm Sean Baker Software Architect Omni Hotels (402) 952-6508 pbaker@omnihotels.com Find out why we believe the Lone Star State is even more ideal this summer and about the Ideal Escape leisure package. Call 1-800-The-Omni or visit us at www.omnitexashotels.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/omaha-pm/attachments/20040818/c4348fc1/attachment.htm From hjarce2001 at yahoo.com Wed Aug 18 18:26:42 2004 From: hjarce2001 at yahoo.com (Hugh Jarce) Date: Wed Aug 18 18:26:44 2004 Subject: [Omaha.pm] AI-type string comparisons using Perl... In-Reply-To: <37155.12.160.138.57.1092323548.squirrel@12.160.138.57> Message-ID: <20040818232642.697.qmail@web90007.mail.scd.yahoo.com> Daniel Linder wrote: > I am working on a small script that will compare some text output from > a program and parse out the numbers I want to act upon. Unfortunatly > the output from the script is quite "humanized" and really ugly to > parse using RegExp. > Does anyone know of a perl module/function that can take a template > string and use that to extract the values into variables for further > use? Tough problem, if I understand it correctly. These modules might be worth a look: Disclaimer: I have not used them. This node might provide some ideas: Hugh. __________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail From dan at linder.org Thu Aug 19 09:27:35 2004 From: dan at linder.org (Daniel Linder) Date: Thu Aug 19 09:24:18 2004 Subject: [Omaha.pm] AI-type string comparisons using Perl... In-Reply-To: <20040818232642.697.qmail@web90007.mail.scd.yahoo.com> References: <37155.12.160.138.57.1092323548.squirrel@12.160.138.57> <20040818232642.697.qmail@web90007.mail.scd.yahoo.com> Message-ID: <56925.12.160.138.72.1092925655.squirrel@12.160.138.72> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > These modules might be worth a look: > > > Disclaimer: I have not used them. > > This node might provide some ideas: > Thanks for the links -- if I make a breakthrough other than the bruit force method I'll pass it along... Dan - - - - - "I do not fear computer, I fear the lack of them." -- Isaac Asimov -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBJLjXNiBNyqUzGb8RAnXbAJwLsmm8vWTSNMQqYI24aRfvUAuILgCdHplf eY6SitOAo7Dd+jhhT1nUnyk= =TK3B -----END PGP SIGNATURE----- From jay at jays.net Sun Aug 22 21:47:18 2004 From: jay at jays.net (Jay Hannah) Date: Sun Aug 22 21:46:59 2004 Subject: [Omaha.pm] Perl blogs Message-ID: In an attempt to be cool like http://planet.perl.org I now have a Perl blog. I replied to a thread about OO class design tonight. If you're into OO or D&D, have a read. -grin- http://use.perl.org/~jhannah j From Kent.Tegels at hdrinc.com Mon Aug 23 07:16:28 2004 From: Kent.Tegels at hdrinc.com (Tegels, Kent) Date: Mon Aug 23 07:18:37 2004 Subject: [Omaha.pm] Perl blogs Message-ID: <8046479841F5F84C9BD1F5CF4AD4379E035C13@OMA-G-L.intranet.hdr> (No journal entries.) ? ________________________________ From: omaha-pm-bounces@mail.pm.org on behalf of Jay Hannah Sent: Sun 8/22/2004 9:47 PM To: omaha-pm@pm.org Subject: [Omaha.pm] Perl blogs In an attempt to be cool like http://planet.perl.org I now have a Perl blog. I replied to a thread about OO class design tonight. If you're into OO or D&D, have a read. -grin- http://use.perl.org/~jhannah j _______________________________________________ Omaha-pm mailing list Omaha-pm@mail.pm.org http://www.pm.org/mailman/listinfo/omaha-pm -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 3518 bytes Desc: not available Url : http://mail.pm.org/pipermail/omaha-pm/attachments/20040823/e7c95516/attachment.bin From jhannah at omnihotels.com Mon Aug 23 15:23:22 2004 From: jhannah at omnihotels.com (Jay Hannah) Date: Mon Aug 23 15:24:03 2004 Subject: [Omaha.pm] RE: figure this one out In-Reply-To: Message-ID: <002601c4894f$0a2ab810$4722000a@omarests2> From: Patrick Baker [mailto:bakep@cox.net] > > http://www.mrgoodbeer.com/games/wacko.shtml > > Woah. -spoiler attached- Play the game above first if you want to. --- (I spent about 8 minutes on this.) Run the math on all possible choices: #!/usr/bin/perl foreach $pick (10..99) { ($a, $b) = ($pick =~ /(\d)(\d)/); $result = $pick - ($a + $b); print "$pick: $result\n"; } No matter what number you pick, there are only 9 possible results. If you look at the pictures associated with those 9 results, they're all the same. The game changes which picture will be the answer for each run, but there's only 1 possible answer, and that's the result it "guesses". j From pbaker at omnihotels.com Mon Aug 23 16:23:54 2004 From: pbaker at omnihotels.com (Patrick Sean Baker) Date: Mon Aug 23 16:24:08 2004 Subject: [Omaha.pm] RE: figure this one out Message-ID: <200408232123.i7NLNsD3019260@magellan.omnihotels.com> GJ. I didn't write a Perl script to figure it out. I noticed that these series of numbers always gave the same result when you added the first two digits together. It didn't dawn on me until I saw the picture changing as you described. 90-99 = 81 80-89 = 72 70-79 = 63 etc... > > From: Patrick Baker [mailto:bakep@cox.net] > > > > http://www.mrgoodbeer.com/games/wacko.shtml > > > > Woah. > > > > -spoiler attached- > > > Play the game above first if you want to. > > > > --- > > (I spent about 8 minutes on this.) > > Run the math on all possible choices: > > #!/usr/bin/perl > foreach $pick (10..99) { > ($a, $b) = ($pick =~ /(\d)(\d)/); > $result = $pick - ($a + $b); > print "$pick: $result\n"; > } > > No matter what number you pick, there are only 9 possible results. If you look at the pictures associated with those 9 results, they're all the same. The game changes which picture will be the answer for each run, but there's only 1 possible answer, and that's the result it "guesses". > > j > > > > > _______________________________________________ > Omaha-pm mailing list > Omaha-pm@mail.pm.org > http://www.pm.org/mailman/listinfo/omaha-pm > > Patrick Baker Programmer (402) 952-6508 pbaker@omnihotels.com From pbaker at omnihotels.com Mon Aug 23 16:23:54 2004 From: pbaker at omnihotels.com (Patrick Sean Baker) Date: Mon Aug 23 16:24:13 2004 Subject: [Omaha.pm] RE: figure this one out Message-ID: <200408232123.i7NLNsD3019260@magellan.omnihotels.com> GJ. I didn't write a Perl script to figure it out. I noticed that these series of numbers always gave the same result when you added the first two digits together. It didn't dawn on me until I saw the picture changing as you described. 90-99 = 81 80-89 = 72 70-79 = 63 etc... > > From: Patrick Baker [mailto:bakep@cox.net] > > > > http://www.mrgoodbeer.com/games/wacko.shtml > > > > Woah. > > > > -spoiler attached- > > > Play the game above first if you want to. > > > > --- > > (I spent about 8 minutes on this.) > > Run the math on all possible choices: > > #!/usr/bin/perl > foreach $pick (10..99) { > ($a, $b) = ($pick =~ /(\d)(\d)/); > $result = $pick - ($a + $b); > print "$pick: $result\n"; > } > > No matter what number you pick, there are only 9 possible results. If you look at the pictures associated with those 9 results, they're all the same. The game changes which picture will be the answer for each run, but there's only 1 possible answer, and that's the result it "guesses". > > j > > > > > _______________________________________________ > Omaha-pm mailing list > Omaha-pm@mail.pm.org > http://www.pm.org/mailman/listinfo/omaha-pm > > Patrick Baker Programmer (402) 952-6508 pbaker@omnihotels.com From jay at jays.net Tue Aug 24 00:55:08 2004 From: jay at jays.net (Jay Hannah) Date: Tue Aug 24 00:54:43 2004 Subject: [Omaha.pm] Perl blogs In-Reply-To: <8046479841F5F84C9BD1F5CF4AD4379E035C13@OMA-G-L.intranet.hdr> References: <8046479841F5F84C9BD1F5CF4AD4379E035C13@OMA-G-L.intranet.hdr> Message-ID: <2763F002-F592-11D8-893D-000A95E317B8@jays.net> On Aug 23, 2004, at 7:16 AM, Tegels, Kent wrote > (No journal entries.) > ? Not yet. But I have posted 2 comments now. > http://use.perl.org/~jhannah j From td3201 at gmail.com Wed Aug 25 09:43:02 2004 From: td3201 at gmail.com (Terry) Date: Wed Aug 25 09:43:05 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table Message-ID: <8ee0610104082507436a396b79@mail.gmail.com> Hello, I have a very ugly script that simply reads in a file, parses and outputs HTML formatted text. See my kludge at the end of the email. The program is invoked as ./program $option where $option can be a number of different things. For this example I will say $option = asdf. I am almost embarrassed to post this code cuz I suck so bad at this....but that's life. I have a pipe ( | ) delimited file that can be a lot different in that the headers of the fields can change based on the user input. That is why I need to set the table headers depending on what the user inputs (print_asdf). That is also why I have different field numbers in do_asdf based on the user input. Right now I only have an example for one user input, "asdf". There could be as many as 20, I think, perhaps more. With all this information, I have two questions: 1) Any better way to handle this varied data other than a sub for each data type/user input? 2) How can I call the subroutines based on the user input? Obviously &print_$foo as I have below doesn't work. Maybe a dispatch table would work but I can't get that to work the way I want either. Thanks! Terry $who = $ARGV[0]; $file = "/RPAR.08242004112402.00"; open(F, $file ) or die ("cant open"); print < Report

EOF &print_$; @lines = ; $records = @lines; # For each record for( $rcounter=0; $rcounter < $records; $rcounter++) { print "


\t

\n"; @fields = split(/\|/,$lines[$rcounter]); $len = @fields; # For each field in that record &do_$who; print "\t\n

\n\n"; } print < EOF sub print_asdf { print <Source EOF } sub do_asdf { for $fcounter (0..4,6,36,37,52) { ($foo) = $fields[$fcounter] =~ /\s*(\S*)\s*/; if ($fcounter eq 0) { print "\t\t\n"; } else { print "\t\t\n"; } } } From hostetlerm at gmail.com Wed Aug 25 09:56:25 2004 From: hostetlerm at gmail.com (Mike Hostetler) Date: Wed Aug 25 09:56:28 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table In-Reply-To: <8ee0610104082507436a396b79@mail.gmail.com> References: <8ee0610104082507436a396b79@mail.gmail.com> Message-ID: On Wed, 25 Aug 2004 09:43:02 -0500, Terry wrote: > Hello, > > I have a very ugly script that simply reads in a file, parses and > outputs HTML formatted text. See my kludge at the end of the email. > > The program is invoked as ./program $option where $option can be a > number of different things. For this example I will say $option = > asdf. I am almost embarrassed to post this code cuz I suck so bad > at this....but that's life. > Take a look at using Getopt or Getopt::Long. They should be standard with your Perl, and they make life easier. Do a "perldoc Getopt" for more info. A decent page for it is at: http://www.aplawrence.com/Unix/perlgetopts.html -- Mike Hostetler thehaas@binary.net http://www.binary.net/thehaas From jay at jays.net Wed Aug 25 18:26:11 2004 From: jay at jays.net (Jay Hannah) Date: Wed Aug 25 18:25:45 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table In-Reply-To: References: <8ee0610104082507436a396b79@mail.gmail.com> Message-ID: <26969BEA-F6EE-11D8-A839-000A95E317B8@jays.net> What's a dispatch table? -grin- On Aug 25, 2004, at 9:56 AM, Mike Hostetler wrote: > Take a look at using Getopt or Getopt::Long. They should be standard > with your Perl, and they make life easier. Do a "perldoc Getopt" for > more info. A decent page for it is at: > > http://www.aplawrence.com/Unix/perlgetopts.html Yes. Getopt::Long rules. > 1) Any better way to handle this varied data other than a sub for each > data type/user input? If the different do_'s are similar, you should write one (or a few) very smart do_* subs, instead of having a seperate sub for each. If each operation is wildly different from the last, you'll end up with one sub per operation. If your code gets long (>500 lines?), you should probably split the subs into different modules. Just move logical groups of subs out of your main program into a .pm file... MyPackage.pm: (what would make them similar?) package MyPackage; sub do_x1 { } sub do_x2 { } ... 1; Then in you main program, at the top: use MyPackage; That's all there is to know. You're writing packages now. Neat huh? When that gets boring, turn your packages into classes and scream OOP! at the top of your longs. Objects are good for the soul. > 2) How can I call the subroutines based on the user input? Obviously > &print_$foo as I have below doesn't work. Maybe a dispatch table > would work but I can't get that to work the way I want either. [jhannah-mac:~/tmp2] jhannah% cat j.pl #!/usr/bin/perl my $who = $ARGV[0]; &{"do_$who"}; sub do_x { print "otay, I'll do_x\n"; } sub do_y { print "otay, I'll do_y\n"; } [jhannah-mac:~/tmp2] jhannah% ./j.pl x otay, I'll do_x [jhannah-mac:~/tmp2] jhannah% ./j.pl y otay, I'll do_y [jhannah-mac:~/tmp2] jhannah% ./j.pl z Undefined subroutine &main::do_z called at ./j.pl line 4. HTH, j From jay at jays.net Wed Aug 25 18:29:46 2004 From: jay at jays.net (Jay Hannah) Date: Wed Aug 25 18:29:18 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table In-Reply-To: <26969BEA-F6EE-11D8-A839-000A95E317B8@jays.net> References: <8ee0610104082507436a396b79@mail.gmail.com> <26969BEA-F6EE-11D8-A839-000A95E317B8@jays.net> Message-ID: On Aug 25, 2004, at 6:26 PM, Jay Hannah wrote: > scream OOP! at the top of your longs errr... s/longs/lungs/ grin, j From td3201 at gmail.com Wed Aug 25 21:29:44 2004 From: td3201 at gmail.com (Terry) Date: Wed Aug 25 21:29:46 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table In-Reply-To: References: <8ee0610104082507436a396b79@mail.gmail.com> <26969BEA-F6EE-11D8-A839-000A95E317B8@jays.net> Message-ID: <8ee061010408251929103f6c15@mail.gmail.com> I have two sets of subs. One set has similarities and so does the other. The problem is that they are invoked at different times in main. So I don't know how to have them all in one sub. This is getting pretty confusing. I think I am going to implement what you suggested with separate subs for each to start with. I will call it 0.1. I will re-invent the ocean in 0.2. :) On Wed, 25 Aug 2004 18:29:46 -0500, Jay Hannah wrote: > > On Aug 25, 2004, at 6:26 PM, Jay Hannah wrote: > > scream OOP! at the top of your longs > > errr... > > s/longs/lungs/ > > grin, > > > > j > > _______________________________________________ > Omaha-pm mailing list > Omaha-pm@mail.pm.org > http://www.pm.org/mailman/listinfo/omaha-pm > From jay at jays.net Wed Aug 25 22:44:10 2004 From: jay at jays.net (Jay Hannah) Date: Wed Aug 25 22:43:47 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table In-Reply-To: <8ee061010408251929103f6c15@mail.gmail.com> References: <8ee0610104082507436a396b79@mail.gmail.com> <26969BEA-F6EE-11D8-A839-000A95E317B8@jays.net> <8ee061010408251929103f6c15@mail.gmail.com> Message-ID: <3097746D-F712-11D8-8AA4-000A95E317B8@jays.net> On Aug 25, 2004, at 9:29 PM, Terry wrote: > I have two sets of subs. One set has similarities and so does the > other. Perhaps you should probably have 2 packages, as I described earlier. Group the subs by concept, and have one package per concept. Easier to maintain and support in the long run. $ cat p1.pm package p1; sub x { print "x"; } 1; $ cat p2.pm package p2; use Exporter; @ISA = qw(Exporter); @EXPORT = qw(&y &z); sub y { print "y"; } sub z { print "z"; } sub a { print "a"; } 1; $ cat j.pl #!/usr/bin/perl use p1; use p2; # You can explicitly identify the packages your subs are in &p1::x; &p2::y; # Or if your .pm's export their subs, like p2.pm does, you can call # the sub # as if it were defined in main. (Not necessarily recommended.) # see perldoc Exporter &y; &z; $ ./j.pl xyyz$ > The problem is that they are invoked at different times in > main. So I don't know how to have them all in one sub. You can invoke any sub that lives anywhere at any time. perl has not problem with that. Whether or not you could/should have one smart subroutine is a separate question. It depends on what the subs are doing and how similar the different subs are. If you get a few of your subs written you might want to post 'em, and see if anyone has any tips. > This is > getting pretty confusing. I think I am going to implement what you > suggested with separate subs for each to start with. I will call it > 0.1. I will re-invent the ocean in 0.2. :) Yup. Start writing subs, and if you see that you're writing similar blocks of code, go back and make your code smarter and shorter. Nowadays, that's called "refactoring". It's good for you. -grin- j From hjarce2001 at yahoo.com Thu Aug 26 04:29:55 2004 From: hjarce2001 at yahoo.com (Hugh Jarce) Date: Thu Aug 26 04:29:57 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table In-Reply-To: <26969BEA-F6EE-11D8-A839-000A95E317B8@jays.net> Message-ID: <20040826092955.22271.qmail@web90005.mail.scd.yahoo.com> Jay Hannah wrote: > [jhannah-mac:~/tmp2] jhannah% cat j.pl > #!/usr/bin/perl > > my $who = $ARGV[0]; > &{"do_$who"}; > > sub do_x { > print "otay, I'll do_x\n"; > } > sub do_y { > print "otay, I'll do_y\n"; > } > > [jhannah-mac:~/tmp2] jhannah% ./j.pl x > otay, I'll do_x > [jhannah-mac:~/tmp2] jhannah% ./j.pl y > otay, I'll do_y > [jhannah-mac:~/tmp2] jhannah% ./j.pl z > Undefined subroutine &main::do_z called at ./j.pl line 4. Nice idea. Here's a version of that idea that works with use strict (and with a bit more error handling): #!/usr/bin/perl use strict; sub Handler::x { print "otay, I'll do_x\n"; } sub Handler::y { print "otay, I'll do_y\n"; } my $who = $ARGV[0]; &{$Handler::{$who} || sub { die "don't know how to do $who\n" }}; However, I might write it with a manual dispatch table like this, because it's faster. ;-) #!/usr/bin/perl use strict; sub do_x { print "otay, I'll do_x\n"; } sub do_y { print "otay, I'll do_y\n"; } my %dispatch_table = ( x => \&do_x, y => \&do_y, ); my $who = $ARGV[0]; exists($dispatch_table{$who}) or die "don't know how to do $who\n"; $dispatch_table{$who}->(); Hugh. __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail From scott.l.miller at hp.com Thu Aug 26 10:37:30 2004 From: scott.l.miller at hp.com (Miller, Scott L (Omaha Networks)) Date: Thu Aug 26 10:37:35 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table Message-ID: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E685@omaexc11.americas.cpqcorp.net> Terry, As Mike & Jay said in their posts, the get options packages are great. Although this is a bit beyond what you're asking for, I have a standard routine to allow the short options (single character options) and object files to be intermingled: ############################################### #allow options to be intermixed with filenames ############################################### while(@ARGV) { #if it doesn't start with a '-', assume it's not an cmd line option while($ARGV[0] =~ /^[^\-]/) { push @hold, shift @ARGV; } getopts(''); } @ARGV=@hold; And I've got a largish program that calls a routine whose name we have in a variable, I have this little routine to help do some error checking: ####################################################################### # Call the appropriate handling routine base on the box type given. # # Ok, I was (and still am) lazy and used dashes in "box-type" strings, # which are (or should be) specified within the ip-2-name.tbl file. # These files were all setup before I thought "Why don't I just name # the subroutines the same thing, and call those routines indirectly?" # # Dashes are not legal characters for any variable/subroutine name # because the parser would get confused because it thinks dashes are # instructions to subtract. # # I also need to check for the case where we don't know what kind # of box a particular message is from. And the case where the routine # isn't defined. In these cases we call a default routine. # ####################################################################### sub call_sub { my $sub = @_[0]; # translate upper case to lower, and more importantly, dashes to # underscores $sub =~ tr/A-Z\-/a-z_/; if ($sub eq "") { &unknown_box; } else { if( defined &$sub ) { &$sub; } else { print "no <$sub> subroutine defined - using unknown_box routine\n"; &unknown_box; } } } #greatly simplified program starts here while(<>) { $type = &get_box_type($_); &call_sub( $type ); #call the appropriate box-type handling subroutine } -Scott From scott.l.miller at hp.com Thu Aug 26 11:01:01 2004 From: scott.l.miller at hp.com (Miller, Scott L (Omaha Networks)) Date: Thu Aug 26 11:01:12 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table Message-ID: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E686@omaexc11.americas.cpqcorp.net> Oh, I forgot one other trick I like to use. If you pipe something into a perl script AND want the routine to parse the input of another file, well that just doesn't work with the magic spaceship (<>). You have to do something like this: #### process data from STDIN if piped in if(! -t) { while() { &process_line; } } #### Read through the object files (to be given on cmd line) if(scalar(@ARGV) > 0) { while (<>) { &process_line; } } Otherwise the (<>) will either ignore because there are filename on ARGV, or ignore the filenames because it's got stuff to process on . It's been too long since I ran into the problem to remember which... -Scott From jhannah at omnihotels.com Thu Aug 26 11:35:40 2004 From: jhannah at omnihotels.com (Jay Hannah) Date: Thu Aug 26 15:32:11 2004 Subject: [Omaha.pm] RE: wrong In-Reply-To: <200408261628.i7QGSZsU007363@mail-omaha.omnihotels.com> Message-ID: <001001c48b8a$b9dc3260$4722000a@omarests2> > my ($lname, $fname) = ($res->get_gst_name =~ /^(\w+)(,|\/)(\w+)$/); > > what's wrong with this? Ya. That's bad. The , or / will be stuck in $fname. Perhaps: #^(.*?)[,/](.*)$# j From jay at jays.net Thu Aug 26 18:01:06 2004 From: jay at jays.net (Jay Hannah) Date: Thu Aug 26 18:00:41 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table In-Reply-To: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E686@omaexc11.americas.cpqcorp.net> References: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E686@omaexc11.americas.cpqcorp.net> Message-ID: On Aug 26, 2004, at 11:01 AM, Miller, Scott L (Omaha Networks) wrote: > Otherwise the (<>) will either ignore because there are > filename > on ARGV, or ignore the filenames because it's got stuff to process on > . It's been too long since I ran into the problem to remember > which... If does one or the other, depending. -grin- perldoc perlop: The null filehandle <> is special: it can be used to emulate the behav- ior of sed and awk. Input from <> comes either from standard input, or from each file listed on the command line. Here's how it works: the first time <> is evaluated, the @ARGV array is checked, and if it is empty, $ARGV[0] is set to "-", which when opened gives you standard input. The @ARGV array is then processed as a list of filenames. The loop while (<>) { ... # code for each line } is equivalent to the following Perl-like pseudo code: unshift(@ARGV, '-') unless @ARGV; while ($ARGV = shift) { open(ARGV, $ARGV); while () { ... # code for each line } } except that it isn't so cumbersome to say, and will actually work. It really does shift the @ARGV array and put the current filename into the $ARGV variable. It also uses filehandle ARGV internally--<> is just a synonym for , which is magical. (The pseudo code above doesn't work because it treats as non-magical.) You can modify @ARGV before the first <> as long as the array ends up containing the list of filenames you really want. Line numbers ($.) continue as though the input were one big happy file. See the example in "eof" in perlfunc for how to reset line numbers on each file. I've always wanted what <> does -- files *or* wait for STDIN. I suppose you could kludge up something to do files, then wait for STDIN...? You'd always *have to* have STDIN, though... j From jay at jays.net Thu Aug 26 18:06:42 2004 From: jay at jays.net (Jay Hannah) Date: Thu Aug 26 18:06:15 2004 Subject: [Omaha.pm] RE: wrong In-Reply-To: <001001c48b8a$b9dc3260$4722000a@omarests2> References: <001001c48b8a$b9dc3260$4722000a@omarests2> Message-ID: <984EC62A-F7B4-11D8-8859-000A95E317B8@jays.net> On Aug 26, 2004, at 11:35 AM, Jay Hannah wrote: >> my ($lname, $fname) = ($res->get_gst_name =~ /^(\w+)(,|\/)(\w+)$/); >> >> what's wrong with this? > > > Ya. That's bad. The , or / will be stuck in $fname. > > Perhaps: #^(.*?)[,/](.*)$# Whoops. I was told that doesn't work. Probably because if you choose to change // to ## you have to specify the s (substitute) or m (match) explicitly. $ cat j.pl #!/usr/bin/perl $_ = "Hannah, Jay"; ($lname, $fname) = m#^(.*?)[,/](.*)$#; print "[$lname][$fname]\n"; $ ./j.pl [Hannah][ Jay] That's better. But still not right, since the leading space in $fname doesn't go away. What this problem needs is Test::Simple and 50 tests. -grin- j From pbaker at omnihotels.com Thu Aug 26 18:59:11 2004 From: pbaker at omnihotels.com (Patrick Sean Baker) Date: Thu Aug 26 18:59:14 2004 Subject: [Omaha.pm] RE: wrong Message-ID: <200408262359.i7QNxBVC007792@magellan.omnihotels.com> I actually like your new way: ($lname, $fname) = m#^(.*?)[,/]\s+(.*)$#; Somehow, it's much easier to read for me..... > > On Aug 26, 2004, at 11:35 AM, Jay Hannah wrote: > >> my ($lname, $fname) = ($res->get_gst_name =~ /^(\w+)(,|\/)(\w+) $/); > >> > >> what's wrong with this? > > > > > > Ya. That's bad. The , or / will be stuck in $fname. > > > > Perhaps: #^(.*?)[,/](.*)$# > > Whoops. I was told that doesn't work. Probably because if you choose to > change // to ## you have to specify the s (substitute) or m (match) > explicitly. > > $ cat j.pl > #!/usr/bin/perl > $_ = "Hannah, Jay"; > ($lname, $fname) = m#^(.*?)[,/](.*)$#; > print "[$lname][$fname]\n"; > > $ ./j.pl > [Hannah][ Jay] > > That's better. But still not right, since the leading space in $fname > doesn't go away. > > What this problem needs is Test::Simple and 50 tests. -grin- > > j > > _______________________________________________ > Omaha-pm mailing list > Omaha-pm@mail.pm.org > http://www.pm.org/mailman/listinfo/omaha-pm > > Patrick Baker Programmer (402) 952-6508 pbaker@omnihotels.com From scott.l.miller at hp.com Fri Aug 27 10:21:06 2004 From: scott.l.miller at hp.com (Miller, Scott L (Omaha Networks)) Date: Fri Aug 27 10:21:10 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table Message-ID: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E68A@omaexc11.americas.cpqcorp.net> Jay wrote: > I suppose you could kludge up something to do files, then wait for STDIN...? Hmm, from the documentation you quoted below, unless you do something somewhat silly like: @stinary = ; #slurp up all input from STDIN which could eat a huge amount of memory, I think you have to process STDIN before the files. I think that behavior is what I would expect anyway as you have to have a process generate some output first before that output can be piped into this program. Since that output was created first, it should be processed before any files that might also happen to be on the command line of this program. Said another way, you expect the files supplied on the command line to be processed in order, STDIN is usually on the line before the program even: cat somefile.txt | thisprogram.pl process-this-file.too and-this.one Therefore, the STDIN stuff comes before the first filename listed... I don't use the backward pipe much (ever?), is it correct to be able to say thisprogram.pl < somefile.txt ? And if so, can you also supply other files for thisprogram.pl to process? After a few quick tests, I don't think this is valid under UNIX. I seem to be remembering DOS's broken version of 'more' many many years ago... > You'd always *have to* have STDIN, though... I just tested this, it sucessfully ignores STDIN, and processes the filelist close STDIN; while(<>) { print $_; } -Scott -----Original Message----- From: omaha-pm-bounces@mail.pm.org [mailto:omaha-pm-bounces@mail.pm.org]On Behalf Of Jay Hannah Sent: Thursday, August 26, 2004 6:01 PM To: Perl Mongers of Omaha, Nebraska USA Subject: Re: [Omaha.pm] bad perl - need help - dispatch table On Aug 26, 2004, at 11:01 AM, Miller, Scott L (Omaha Networks) wrote: > Otherwise the (<>) will either ignore because there are > filename > on ARGV, or ignore the filenames because it's got stuff to process on > . It's been too long since I ran into the problem to remember > which... If does one or the other, depending. -grin- perldoc perlop: The null filehandle <> is special: it can be used to emulate the behav- ior of sed and awk. Input from <> comes either from standard input, or from each file listed on the command line. Here's how it works: the first time <> is evaluated, the @ARGV array is checked, and if it is empty, $ARGV[0] is set to "-", which when opened gives you standard input. The @ARGV array is then processed as a list of filenames. The loop while (<>) { ... # code for each line } is equivalent to the following Perl-like pseudo code: unshift(@ARGV, '-') unless @ARGV; while ($ARGV = shift) { open(ARGV, $ARGV); while () { ... # code for each line } } except that it isn't so cumbersome to say, and will actually work. It really does shift the @ARGV array and put the current filename into the $ARGV variable. It also uses filehandle ARGV internally--<> is just a synonym for , which is magical. (The pseudo code above doesn't work because it treats as non-magical.) You can modify @ARGV before the first <> as long as the array ends up containing the list of filenames you really want. Line numbers ($.) continue as though the input were one big happy file. See the example in "eof" in perlfunc for how to reset line numbers on each file. I've always wanted what <> does -- files *or* wait for STDIN. I suppose you could kludge up something to do files, then wait for STDIN...? You'd always *have to* have STDIN, though... j _______________________________________________ Omaha-pm mailing list Omaha-pm@mail.pm.org http://www.pm.org/mailman/listinfo/omaha-pm From dan at linder.org Fri Aug 27 16:02:45 2004 From: dan at linder.org (Daniel Linder) Date: Fri Aug 27 15:59:13 2004 Subject: [Omaha.pm] RE: wrong In-Reply-To: <200408262359.i7QNxBVC007792@magellan.omnihotels.com> References: <200408262359.i7QNxBVC007792@magellan.omnihotels.com> Message-ID: <30871.12.160.138.70.1093640565.squirrel@12.160.138.70> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > I actually like your new way: > ($lname, $fname) = m#^(.*?)[,/]\s+(.*)$#; Wouldn't this work the same (and save one byte golfing...): ($lname, $fname) = m#^(.*?)[,/ ]+(.*)$#; On Aug 26, 2004, at 11:35 AM, Jay Hannah wrote: > my ($lname, $fname) = ($res->get_gst_name =~ /^(\w+)(,|\/)(\w+)$/); This would have worked modifying the left side of the "=", right? my ($lname, $foo, $fname) = ($res->get_gst_name =~ /^(\w+)(,|\/)(\w+)$/); (Then just ignore $foo...) $ cat /tmp/d.pl #!/usr/bin/perl $_ = "Linder, Dan"; ($lname, $fname) = m#^(.*?)[,/]\s+(.*)$#; print "[$lname][$fname]\n"; $_ = "Linder, Dan"; ($lname, $fname) = m#^(.*?)[,/ ]+(.*)$#; print "[$lname][$fname]\n"; $ /tmp/d.pl [Linder][Dan] [Linder][Dan] Dan - - - - - "I do not fear computer, I fear the lack of them." -- Isaac Asimov -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBL6F1NiBNyqUzGb8RAt++AJ9u59omqvArlbAEllWohMcyov0/XQCfQxPv wQHHVTjQ+Zs/D1sRuEEV+3M= =/JJC -----END PGP SIGNATURE----- From hjarce2001 at yahoo.com Sat Aug 28 21:30:24 2004 From: hjarce2001 at yahoo.com (Hugh Jarce) Date: Sat Aug 28 21:30:26 2004 Subject: [Omaha.pm] bad perl - need help - dispatch table In-Reply-To: <1F7C0C8F4BD7C54A8BC55012FEF3DF6D0302E68A@omaexc11.americas.cpqcorp.net> Message-ID: <20040829023024.77518.qmail@web90005.mail.scd.yahoo.com> Miller, Scott L wrote: > Said another way, you expect the files supplied on the command line > to be processed in order, STDIN is usually on the line before the > program even: > > cat somefile.txt | thisprogram.pl process-this-file.too and-this.one > > Therefore, the STDIN stuff comes before the first filename listed... No. Here is how a typical UNIX "filter" command works: if you put filenames on the command line, it will read those files (and ignore stdin); with no filenames, it reads stdin. Some commands (including cat and perl) further recognize a special "filename" of - which is just a shorthand for "read stdin". Try it yourself. # cat a.tmp this is file a.tmp # cat b.tmp this is file b.tmp # cat c.tmp this is file c.tmp # cat a.tmp this is file a.tmp # cat is it correct to be able to say > thisprogram.pl < somefile.txt ? Yes. And it is better style (and more efficient) than: cat somefile.txt | thisprogram.pl Quoting Tom Christiansen: "A wise man once said: if you find yourself calling cat with just one argument, then you're probably doing something you shouldn't" See . Hugh. _______________________________ Do you Yahoo!? Win 1 of 4,000 free domain names from Yahoo! Enter now. http://promotions.yahoo.com/goldrush From jay at jays.net Sun Aug 29 00:25:24 2004 From: jay at jays.net (Jay Hannah) Date: Sun Aug 29 00:24:57 2004 Subject: [Omaha.pm] Re: [olug] Expect script help... In-Reply-To: <24541.12.160.138.70.1093539223.squirrel@12.160.138.70> References: <24541.12.160.138.70.1093539223.squirrel@12.160.138.70> Message-ID: Can you show us what success looks like when you run through the entire process manually? j On Aug 26, 2004, at 11:53 AM, Daniel Linder wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Guy, > > Slightly off-topic but I figgured what the heck. :) > > I am trying to automate login to a remote Unix system. I have this > working when my laptop telnets directly to the remote system and the > expect script then ran a script on the remote server to set the > $DISPLAY > variable. > > The situation has changed and I now have to shell into an intermediate > unix system, then run "PowerBroker" to connect in to the final > location. > When my script runs on the remote system now, it can only get the IP > address of the intermediate "PowerBroker" system but not my true > workstation. > > Can some expect or Tcl guru give me some quick pointers to parse the > command output in the expect script to parse out my workstations IP > address so I can send it to a remote system? > > Here is a snippet of my expect code: > > #!/usr/bin/expect > # > # Code to login to the first machine would be here... > # > send "who am i\n"; > # This returns: > # linderd pts/2 Aug 26 10:32 (10.120.15.88) > set MYDISPLAY > # > # Code to login to the second machine would be here... > # > # Now set my workstation DISPLAY variable... > send "DISPLAY=[ $DISPLAY ]:0.0\n"; > > Thanks! > > Dan From dan at linder.org Mon Aug 30 09:35:22 2004 From: dan at linder.org (Daniel Linder) Date: Mon Aug 30 09:31:45 2004 Subject: [Omaha.pm] Re: [olug] Expect script help... In-Reply-To: References: <24541.12.160.138.70.1093539223.squirrel@12.160.138.70> Message-ID: <26939.12.160.138.70.1093876522.squirrel@12.160.138.70> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 (I'm including the PerlMongers group on this too since Jay sent the request to both the PM and OLUG mailing lists... --Dan) > Can you show us what success looks like when you run through the entire > process manually? Ok, here is the script, the output of the login session is below the script - --- begin script --- #!/usr/bin/expect # # Call like this: # login.exp [RemoteSystemName] [RemoteUserName] # # Description: Expect script to automate login to a remote # UNIX system by way of an intermediate "PowerBroker" controlled # server. Script also sets the $DISPLAY variable to the proper # system for displays. set timeout 30; # Retrieve the remote system to login to... set where [lindex $argv 0]; # Retrieve the user to login to the remote system as... set who [lindex $argv 1]; set PowerBrokerUser "" set PowerBrokerPwd "" # Tell the local workstation to allow in # the remote system for X displays spawn xhost +${where} set PowerBrokerServer "" # Login to the PowerBroker server... spawn /usr/bin/telnet ${PowerBrokerServer}; expect "ogin:" send "${PowerBrokerUser}\n" expect "assword:" send "${PowerBrokerPwd}\n" expect "$ " # Get the IP address we are coming from to set the # XWindows DISPLAY variable on the remote system properly send "who am i\n"; expect "$ "; set output_array [split $expect_out(buffer) "("] set ip [lindex $output_array 1] set output_array [split ${ip} ")"] set ip [lindex $output_array 0] set MYDISPLAY "${ip}:0.0" send "pbrun -h $where $who ; exit\n"; expect "assword for "; send "${PowerBrokerPwd}\n"; send "DISPLAY=${MYDISPLAY}\n"; interact - --- End script --- Here is the screen output of a sample run: - --- Begin sample run --- $ ./login.exp remoteserver dlinder spawn xhost +remoteserver spawn /usr/bin/telnet pbroker Trying 10.20.30.40... Connected to 10.2.124.63. Escape character is '^]'. SunOS 5.8 login: dlinder Password: Last login: Mon Aug 30 14:07:08 from 10.1.120.158 Sun Microsystems Inc. SunOS 5.8 Generic Patch October 2001 eutil008 V480 for Non-Production apps $ who am i dlinder pts/2 Aug 30 14:23 (10.1.120.158) $ pbrun -h remoteserver dlinder ; exit Enter password for dlinder: [remoteserver:~] $ DISPLAY=10.1.120.158:0.0 [remoteserver:~] $ - --- End sample run --- There you have it. Thanks everyone for your time, hope this can help someone in the future. So, can someone re-write this in Perl w/ the Expect module? :) Dan - - - - - "I do not fear computer, I fear the lack of them." -- Isaac Asimov -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBMzsqNiBNyqUzGb8RAljkAJ9XHaj/KZ/fHXuEDJnjVn4s0Gb/YwCdERD2 cDtTKhKlY+Bt7HPVf7ueTTY= =Mev2 -----END PGP SIGNATURE----- From jay at jays.net Tue Aug 31 15:44:25 2004 From: jay at jays.net (Jay Hannah) Date: Tue Aug 31 15:43:57 2004 Subject: [Omaha.pm] Re: Expect script help... In-Reply-To: <26939.12.160.138.70.1093876522.squirrel@12.160.138.70> References: <24541.12.160.138.70.1093539223.squirrel@12.160.138.70> <26939.12.160.138.70.1093876522.squirrel@12.160.138.70> Message-ID: <8B756DEC-FB8E-11D8-B603-000A95E317B8@jays.net> On Aug 30, 2004, at 9:35 AM, Daniel Linder wrote: > (I'm including the PerlMongers group on this too since Jay sent the > request to both the PM and OLUG mailing lists... --Dan) ... > So, can someone re-write this in Perl w/ the Expect module? :) Exactly. We moved our tiny little TCL/Expect scripties into Perl's Expect.pm, just so we could stop worrying about installing/upgrading/understanding TCL/Expect. http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod If only someone would port Java into Perl (Java.pm), we could run b2ee_weblogic.pl! or 'use J2EE.pm;' -grin- "When all else fails, you can always use /(TCL\/)?Expect(\.pm)?/." -Me Glad you got it figured out! Cheers, j From jay at jays.net Tue Aug 31 17:32:18 2004 From: jay at jays.net (Jay Hannah) Date: Tue Aug 31 17:31:51 2004 Subject: [Omaha.pm] Re: Expect script help... In-Reply-To: <200408311731.20504@grx> References: <24541.12.160.138.70.1093539223.squirrel@12.160.138.70> <26939.12.160.138.70.1093876522.squirrel@12.160.138.70> <8B756DEC-FB8E-11D8-B603-000A95E317B8@jays.net> <200408311731.20504@grx> Message-ID: <9DC82B92-FB9D-11D8-B603-000A95E317B8@jays.net> On Aug 31, 2004, at 5:31 PM, David Walker wrote: > I've been converting all my old Perl scripts to TCL because it is so > much > easier. Language selection all depends on what you need to accomplish. I like Perl because it can do almost anything. If you only need to do certain things, other tools shine for specific tasks. What kinds of work do you do in TCL? $0.02, j From Kent.Tegels at hdrinc.com Tue Aug 31 21:10:08 2004 From: Kent.Tegels at hdrinc.com (Tegels, Kent) Date: Tue Aug 31 21:10:25 2004 Subject: [Omaha.pm] Re: Expect script help... Message-ID: <8046479841F5F84C9BD1F5CF4AD4379E035C21@OMA-G-L.intranet.hdr> I frequently prototype in Perl for test my thoughts, the redo the code, in well, something else. It's like thinking in English but writing Japanese, I guess. ________________________________ From: omaha-pm-bounces@mail.pm.org on behalf of Jay Hannah Sent: Tue 8/31/2004 5:32 PM To: Omaha Linux User Group Cc: Nebraska USA Perl Mongers of Omaha Subject: [Omaha.pm] Re: Expect script help... On Aug 31, 2004, at 5:31 PM, David Walker wrote: > I've been converting all my old Perl scripts to TCL because it is so > much > easier. Language selection all depends on what you need to accomplish. I like Perl because it can do almost anything. If you only need to do certain things, other tools shine for specific tasks. What kinds of work do you do in TCL? $0.02, j _______________________________________________ Omaha-pm mailing list Omaha-pm@mail.pm.org http://www.pm.org/mailman/listinfo/omaha-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/omaha-pm/attachments/20040831/24fad044/attachment.htm
Destination Input File Output File Date Input Records Filter Name Filter Remove Transmit Output$foo$foo