From MichaelRunningWolf at att.net Tue Apr 1 18:49:15 2003 From: MichaelRunningWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:comp.lang.perl Message-ID: It's depricated, yes? No? One of my ISP's (oz.net) carries these groups. comp.lang.perl comp.lang.perl.announce comp.lang.perl.misc comp.lang.perl.modules comp.lang.perl.moderated If this isn't right, is there some location I can direct them to in order to clue in and unsubscribe? -- Michael R. Wolf All mammals learn by playing! MichaelRunningWolf@att.net From shawnw at speakeasy.org Tue Apr 1 19:15:55 2003 From: shawnw at speakeasy.org (Shawn Wagner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:comp.lang.perl In-Reply-To: ; from MichaelRunningWolf@att.net on Tue, Apr 01, 2003 at 04:49:15PM -0800 References: Message-ID: <20030401171555.A9051@speakeasy.org> On Tue, Apr 01, 2003 at 04:49:15PM -0800, Michael R. Wolf wrote: > > It's depricated, yes? No? Yes. For years. It's a dead newsgroup. -- Shawn Wagner shawnw@speakeasy.org From andrew at sweger.net Tue Apr 1 18:59:47 2003 From: andrew at sweger.net (Andrew Sweger) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:comp.lang.perl In-Reply-To: Message-ID: Wow. I remember usenet. Do people still use that? It's all still there and kicking: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&group=comp.lang.perl On 1 Apr 2003, Michael R. Wolf wrote: > > It's depricated, yes? No? > > One of my ISP's (oz.net) carries these groups. > > comp.lang.perl > comp.lang.perl.announce > comp.lang.perl.misc > comp.lang.perl.modules > comp.lang.perl.moderated > > If this isn't right, is there some location I can direct them to in > order to clue in and unsubscribe? > > > -- Andrew B. Sweger -- The great thing about multitasking is that several things can go wrong at once. From christopher.w.cantrall at boeing.com Tue Apr 1 19:01:29 2003 From: christopher.w.cantrall at boeing.com (Cantrall, Christopher W) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:comp.lang.perl Message-ID: <04088F154165F84E89F96113157E4B610BFCDD@XCH-NW-11.nw.nos.boeing.com> > It's depricated, yes? No? That probably depends on whether you are talking about comp.lang.perl.* or just comp.lang.perl by it's lonesome. I had understood that comp.lang.perl.misc was active, but I don't participate. ________________________________________ Christopher Cantrall Structural Engineer, 767 Fuselage phone: 425-342-4131 fax: 425-717-3174 M/C 0Y-12 -- 40-83 E7 Christopher.W.Cantrall@Boeing.com > -----Original Message----- > From: Michael R. Wolf [mailto:MichaelRunningWolf@att.net] > Sent: Tuesday, April 01, 2003 4:49 PM > To: spug-list@pm.org > Subject: SPUG:comp.lang.perl > > > > It's depricated, yes? No? > > One of my ISP's (oz.net) carries these groups. > > comp.lang.perl > comp.lang.perl.announce > comp.lang.perl.misc > comp.lang.perl.modules > comp.lang.perl.moderated > > If this isn't right, is there some location I can direct them to in > order to clue in and unsubscribe? > > > -- > Michael R. Wolf > All mammals learn by playing! > MichaelRunningWolf@att.net > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: www.seattleperl.org > > From shawnw at speakeasy.org Tue Apr 1 19:28:13 2003 From: shawnw at speakeasy.org (Shawn Wagner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:comp.lang.perl In-Reply-To: ; from MichaelRunningWolf@att.net on Tue, Apr 01, 2003 at 04:49:15PM -0800 References: Message-ID: <20030401172813.B9051@speakeasy.org> On Tue, Apr 01, 2003 at 04:49:15PM -0800, Michael R. Wolf wrote: > > If this isn't right, is there some location I can direct them to in > order to clue in and unsubscribe? Forgot about this. perlfaq2 mentions the demise of the comp.lang.perl group, and I'm sure there's plenty of other places that will as well. -- Shawn Wagner shawnw@speakeasy.org From mark.johnston at pnl.gov Tue Apr 1 19:20:15 2003 From: mark.johnston at pnl.gov (Johnston, Mark) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:comp.lang.perl Message-ID: ... and their are still discussions going on in the newsgroup on the topic ... (http://groups.google.com/groups?hl=en&lr=&ie=ISO-8859-1&scoring=d&q=perlfaq2+%22comp.lang.perl%22+defunct&btnG=Google+Search) --Mark -----Original Message----- From: Shawn Wagner [mailto:shawnw@speakeasy.org] Sent: Tuesday, April 01, 2003 5:16 PM To: spug-list@pm.org Subject: Re: SPUG:comp.lang.perl On Tue, Apr 01, 2003 at 04:49:15PM -0800, Michael R. Wolf wrote: > > It's depricated, yes? No? Yes. For years. It's a dead newsgroup. -- Shawn Wagner shawnw@speakeasy.org _____________________________________________________________ Seattle Perl Users Group Mailing List POST TO: spug-list@mail.pm.org ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list MEETINGS: 3rd Tuesdays, U-District, Seattle WA WEB PAGE: www.seattleperl.org From jay at scherrer.com Tue Apr 1 19:40:04 2003 From: jay at scherrer.com (Jay Scherrer) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:comp.lang.perl In-Reply-To: References: Message-ID: <200304011740.05049.jay@scherrer.com> Michael, These groups are very much alive and listened to in many countries. Especialy if you are submitting a new module. On Tuesday 01 April 2003 04:49 pm, Michael R. Wolf wrote: > It's depricated, yes? No? > > One of my ISP's (oz.net) carries these groups. > > comp.lang.perl > comp.lang.perl.announce used for announcing new fetures and new ports to perl. > comp.lang.perl.misc > comp.lang.perl.modules used for discusion of module creation > comp.lang.perl.moderated > > If this isn't right, is there some location I can direct them to in > order to clue in and unsubscribe? From richard at richard-anderson.org Tue Apr 1 20:33:03 2003 From: richard at richard-anderson.org (Richard Anderson) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:comp.lang.perl References: Message-ID: <3e8a4bdf4e8855.38169569@zipcon.com> The best way to determine the amount of activity in a Usenet newsgroup is to use Google's interface. (They are now the keeper of the archive, anyway.) To see the current activity in all the comp.lang.perl.* groups. use this URL: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&group=comp.lang.perl This doesn't show the activity in the root groupt (comp.lang.perl), but you can see that comp.lang.perl is quite active. The root URL for Google's interface is: http://www.google.com/grphp?hl=en&q= -- Richard Anderson richard@richard-anderson.org www.richard-anderson.org inm4taw > > It's depricated, yes? No? > > One of my ISP's (oz.net) carries these groups. > > comp.lang.perl > comp.lang.perl.announce > comp.lang.perl.misc > comp.lang.perl.modules > comp.lang.perl.moderated > > If this isn't right, is there some location I can direct them to in > order to clue in and unsubscribe? > > > -- > Michael R. Wolf > All mammals learn by playing! > MichaelRunningWolf@att.net > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: www.seattleperl.org > > From MichaelRunningWolf at att.net Wed Apr 2 23:23:38 2003 From: MichaelRunningWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:FIRST Robotics Competition -- Thu-Sat Message-ID: It's not Perl, but it seems like the kind of thing that may appeal to you Science and Technology folks. If hardware doesn't interest you, stop reading now. FIRST Robotics Competition is running Thursday-Saturday at "Hec" Ed (beside the U.W. Stadium). In general, Thursday -- practice rounds (9ish - 5ish) Friday -- seeding matches (9ish - 5ish) Saturday -- seeding matches (9ish - 12ish) final rounds (1:00 - 3:00) If you've only got 2 hours, Saturday afternoon should be *hot*, but there will be some kind of match running most of the time. Specifics at http://www.usfirst.org/robotics/2003/agendas/WA_agenda.pdf Free, and open to the public. Did I mention FREE!!! Here's a quote from the program: FIRST (For Inspiration and Recognition of Science and Technology) and foremost... What is FIRST about? FIRST's aim is to get students energized and involved with science and technology. It wants to rid the perception of may kids that science is musty, tedious, and only for nerds with pocket protectors. Find more at wwww.ucfirst.org Come watch some the next generation get excited about science and technology. A techno-catharsis.... -- Michael R. Wolf All mammals learn by playing! MichaelRunningWolf@att.net From matt at rearviewmirror.org Wed Apr 9 12:48:09 2003 From: matt at rearviewmirror.org (Matt Beland) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Modules for Citrix/ICA? Message-ID: <200304091048.09016.matt@rearviewmirror.org> Hello, I'm working on a monitoring application for a client, and need to access a Citrix server to test for various items (response time, published apps, etc.). I distinctly remember running across a set of Perl modules for ICA or Citrix, but I'm not finding anything in the usual places (CPAN, Citrix site, Google.) Am I just getting senile early, or does such a thing exist and I just can't find it? -- Matt Beland matt@rearviewmirror.org http://www.rearviewmirror.org From gregory.v.reed at boeing.com Thu Apr 10 10:26:57 2003 From: gregory.v.reed at boeing.com (Reed, Gregory V) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Perl/Apache Message-ID: <01F3F3540C94B540B82D03E58D97D62366E82C@XCH-NW-08.nw.nos.boeing.com> Does anyone know of any problems existing with: Perl 5.6.1 Apache 1.3.27 When using Mod-Perl module? Thanks, Greg Reed The Boeing Company Client Server Operations Development Server Administration PH. 206-662-3576 PG. 206-797-1905 From cmeyer at helvella.org Thu Apr 10 10:38:32 2003 From: cmeyer at helvella.org (Colin Meyer) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Perl/Apache In-Reply-To: <01F3F3540C94B540B82D03E58D97D62366E82C@XCH-NW-08.nw.nos.boeing.com>; from gregory.v.reed@boeing.com on Thu, Apr 10, 2003 at 08:26:57AM -0700 References: <01F3F3540C94B540B82D03E58D97D62366E82C@XCH-NW-08.nw.nos.boeing.com> Message-ID: <20030410083832.B3009@hobart.helvella.org> On Thu, Apr 10, 2003 at 08:26:57AM -0700, Reed, Gregory V wrote: > Does anyone know of any problems existing with: > > Perl 5.6.1 > Apache 1.3.27 > > When using Mod-Perl module? You should have no problems, though if possible, I would recommend using Perl 5.8.0, or the soon-to-be 5.8.1. Have fun, -Colin. From spud at spudzeppelin.com Thu Apr 10 10:52:45 2003 From: spud at spudzeppelin.com (Jeff Almeida) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Perl/Apache In-Reply-To: <01F3F3540C94B540B82D03E58D97D62366E82C@XCH-NW-08.nw.nos.boeing.com>; from gregory.v.reed@boeing.com on Thu, Apr 10, 2003 at 08:26:57AM -0700 References: <01F3F3540C94B540B82D03E58D97D62366E82C@XCH-NW-08.nw.nos.boeing.com> Message-ID: <20030410105245.A43842@home.offwhite.net> Also Sprach Reed, Gregory V: >Does anyone know of any problems existing with: > Perl 5.6.1 > Apache 1.3.27 >When using Mod-Perl module? There are a number of possible problems, but I'm going to need some more specifics, such as 0S, compiler, dynamic or static mod_perl, precompiled or built-from-source Apache, and so on :) Something to watch for: the number one trap, that catches a number of people, is that Perl, Apache, and mod_perl all ought to be built with the same compiler. So in a commercial Unix, you would often have Perl on the system by default, built with cc, and then you try to go in and build Apache (ok by itself) and then mod_perl with gcc -- and you wind up with a mess in the linker! I hope this helps :) jeff -- ************************************************************ Jeff D. "Spud (Zeppelin)" Almeida Little Elm, TX spud@spudzeppelin.com From tim at consultix-inc.com Thu Apr 10 15:36:41 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:April Meeting: Perl for UNIX Users Message-ID: <20030410133641.A31349@timji.consultix-inc.com> SPUGsters, We had two speakers tentatively lined up for this month's meeting, but both have elected to postpone until May (too distracted by Wars and Taxes, I guess). So I'm stepping into the breach, in order to practice some conference talks and get valuable feedback from the SPUGizens. But if anybody else would like to make a presentation, please let me know and I'll be happy to put you on the schedule too! 8-} Also, I'd like to invite SPUGsters to let their interests be known for upcoming talks. What do you want to learn about? XML? DBI? Benchmarking? Debugging? References? Just post your ideas to the list, and we'll probably find somebody who can educate us on it. And please let us know (post to the list) if you'd like a seat reserved for you at Cedar's before the meeting. ======================================================= | Tim Maher, Ph.D. tim@timmaher.org | | JAWCAR ("Just Another White-Camel Award Recipient") | | SPUG Founder & Leader spug@seattleperl.org | | Seattle Perl Users Group www.seattleperl.org | ======================================================= April 2003 Seattle Perl Users Group Meeting ----------------------------------------------------- Theme: "Perl for UNIX Users" Speaker: Tim Maher, Consultix Time: Tuesday, April 15, 2003 7-9pm Location: SAFECO bldg, Brooklyn St. and NE 45th St. Cost: Admission is free and open to the general public. Info: http://seattleperl.org/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Tim is writing_a_book for Manning_Publications called "Minimal Perl for Shell Users and Programmers". Unlike other Perl books, this one will give the reader advanced standing for existing knowledge of UNIX shell commands and shell programming techniques, and capitalize on that to make Perl easier to learn. In this talk, Tim will feature excerpts from the upcoming book, and his associated conference presentations at Linux_Fest_Northwest, YAPC:: America::North, and The Perl Conference. He looks forward to receiving sage feedback from SPUGsters on what works and doesn't in these presentations! Topics will include: * the Five Perl One-liners all UNIX users should know * three Perl scripts UNIX users shouldn't live without * simple Perl scripts that improve on sed, grep, and awk * how the Shell's looping facilities compare to those of Perl, including o why the Shell's "while" loop is superior to its Perl counterpart o why Perl's "do/while" sucks o when to use the implicit (-n) loop, and when to roll your own o where you can use "goto" without shame o which Shell loop is missing from standard Perl, and how to use it anyway Pre- and Post- Meeting Activities --------------------------------- The pre-meeting dinner will be at the Cedars restaurant, at 50th St. and Brooklyn, in the University District, near the Safeco building where the meeting will take place. The phone number is 527-5247. If you're planning to be there, please RSVP to the list by 2pm on the meeting day with your expected arrival time (5:30-5:45pm is recommended). TO BE FAIR, from now on only those who comply with the RSVP policy (and are therefore counted in the seating reservation) will be allowed to sit at the speaker's table. -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From tim at consultix-inc.com Thu Apr 10 17:54:49 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:April Meeting: Perl for UNIX Users In-Reply-To: <20030410221411.GB4217@wokkil.pair.com> References: <20030410133641.A31349@timji.consultix-inc.com> <20030410221411.GB4217@wokkil.pair.com> Message-ID: <20030410155449.A32215@timji.consultix-inc.com> On Thu, Apr 10, 2003 at 06:14:11PM -0400, Asim Jalis wrote: > On Thu, Apr 10, 2003 at 01:36:41PM -0700, Tim Maher wrote: > > SPUGsters, We had two speakers tentatively lined up for this > > month's meeting, but both have elected to postpone until May > > (too distracted by Wars and Taxes, I guess). So I'm stepping > > into the breach, in order to practice some conference talks and > > get valuable feedback from the SPUGizens. > > Perl has several solutions to the tax problem. What about war? > Does Perl have any modules that could be used in the war? > > Asim The use of the four-argument form of substr() comes to mind. It has the capability of demolishing vital resources with very little effort (or awareness) on the part of the programmer. Consider, for example, my favorite (accidental) invocation of this "feature": $_=join '', 'a' .. 'z' ; print substr $_, 0, 20, "\n"; # show first chars of string print "\n"; # Funny, why's this needed? print "'$_'\n"; The output of course is: abcdefghijklmnopqrst ' uvwxyz' The "\n", as the inadvertent 4th argument to substr(), tells Perl to *replace* the indicated substring [0..19] by the "\n". This bites me a few times a year, and I usually waste time testing other parts of a complex program for far too long before finding it. My advice is to resist the temptation to change print substr $_, 0, 20; into print substr $_, 0, 20,"\n"; In fact, I advise newbies as a general rule to always add the "\n" with a separate call to print(), or by using the -l invocation option; this approach skirts lots of parenthesis-related issues. The cure for the above example is of course to tell the compiler where substr's argument list ends, using parentheses: print substr ($_, 0, 20), "\n"; # show first chars of string Anyway, to get back to the Asim's Saddamical theme: $_="Saddam prevents Iraqi freedom!"; print "$_\n"; $save=sprintf substr $_, 0, 16, "\n"; # store first chars of string print "\U$_\n"; Output: Saddam prevents Iraqi freedom! IRAQI FREEDOM! I hereby offer this example of a WMD (Weapon of Mass Destruction) as a WMI (Weapon of Mass Instruction). -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From MichaelRunningWolf at att.net Thu Apr 10 18:23:27 2003 From: MichaelRunningWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:36:55 2004 Subject: RSVP [was: SPUG:April Meeting: Perl for UNIX Users] In-Reply-To: <20030410133641.A31349@timji.consultix-inc.com> References: <20030410133641.A31349@timji.consultix-inc.com> Message-ID: Tim Maher writes: > And please let us know (post to the list) if you'd like a seat > reserved for you at Cedar's before the meeting. Please reserve me a seat at the big table. Thanks, Michael Wolf -- Michael R. Wolf All mammals learn by playing! MichaelRunningWolf@att.net From MichaelRunningWolf at att.net Thu Apr 10 21:28:14 2003 From: MichaelRunningWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:WMD as I see it In-Reply-To: <20030410155449.A32215@timji.consultix-inc.com> References: <20030410133641.A31349@timji.consultix-inc.com> <20030410221411.GB4217@wokkil.pair.com> <20030410155449.A32215@timji.consultix-inc.com> Message-ID: SPUG-list-owner writes: [...] > My advice is to resist the temptation to change > print substr $_, 0, 20; > into > print substr $_, 0, 20,"\n"; > My advice is to resist the temptation to change > print substr $_, 0, 20; > into > print substr $_, 0, 20,"\n"; > > In fact, I advise newbies as a general rule to always add the "\n" > with a separate call to print(), or by using the -l invocation option; > this approach skirts lots of parenthesis-related issues. Funny, I guess I'd have done it the other way... advise the use of ()'s to avoid operator precedence issues. What's your rationale? With ()'s there's no need to mention precedence. *My* advice would be to _submit_to_the_temptation_ to change print(substr($_, 0, 20)); into print(substr($_, 0, 20), "\n"); Since you're protected by the paren's, you can build as complex as you wish without bumping into an unknown. [...] > Anyway, to get back to the Asim's Saddamical theme: > > $_="Saddam prevents Iraqi freedom!"; > print "$_\n"; > $save=sprintf substr $_, 0, 16, "\n"; # store first chars of string > print "\U$_\n"; > > Output: > Saddam prevents Iraqi freedom! > > IRAQI FREEDOM! $justification = eval {require "compelling U.S. interest"} or eval {require "brain"} or eval {require "conscience"} or eval {require "historical perspective"} or "Continue any way with heightened sense of national insecurity..."; $WMD = "Weapon of Mass Deception"; $subterfuge = "Operation Iraqi Liberation"; @credible_allied_forces = (); $acromony_nym = join "@credible_allied_forces", $subterfuge =~ m/\b(.)/g; if ($acromony_nym eq "O I L") { ($boldface_lie = $subterfuge) =~ s/Liberation/Freedom/; } print "$WMD => $boldface_lie"; > I hereby offer this example of a WMD (Weapon of Mass Destruction) > as a WMI (Weapon of Mass Instruction). Now you see how I interpret the most dangerous WMD. Weapon of Mass Deception => Operation Iraqi Freedom -- Michael R. Wolf All mammals learn by playing! MichaelRunningWolf@att.net From ced at carios2.ca.boeing.com Thu Apr 10 21:21:58 2003 From: ced at carios2.ca.boeing.com (ced@carios2.ca.boeing.com) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:WMD as I see it Message-ID: <200304110221.TAA01889@carios2.ca.boeing.com> > Funny, I guess I'd have done it the other way... advise the use of > ()'s to avoid operator precedence issues. What's your rationale? > With ()'s there's no need to mention precedence. Or send in the Deparse squad: perl -MO=Deparse -le 'print substr $foo,0,16,"\n"' print substr($foo, 0, 16, "\n"); -e syntax OK you can catch a few WMD's hiding in the dunes... Rgds, -- Charles DeRykus From doug at beaver.net Thu Apr 10 22:40:58 2003 From: doug at beaver.net (Doug Beaver) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:WMD as I see it In-Reply-To: ; from MichaelRunningWolf@att.net on Thu, Apr 10, 2003 at 07:28:14PM -0700 References: <20030410133641.A31349@timji.consultix-inc.com> <20030410221411.GB4217@wokkil.pair.com> <20030410155449.A32215@timji.consultix-inc.com> Message-ID: <20030410234058.A77781@beaver.net> On Thu, Apr 10, 2003 at 07:28:14PM -0700, Michael R. Wolf wrote: > Weapon of Mass Deception => Operation Iraqi Freedom can we please keep politics off the spug list? unless we're talking about p5p? :-) thanks, doug -- "Contrary to what most people say, the most dangerous animal in the world is not the lion or the tiger or even the elephant. It's a shark riding on an elephant's back, just trampling and eating everything they see." -- Jack Handey From MichaelRunningWolf at att.net Sat Apr 12 22:17:02 2003 From: MichaelRunningWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:WMD as I see it In-Reply-To: <20030410234058.A77781@beaver.net> References: <20030410133641.A31349@timji.consultix-inc.com> <20030410221411.GB4217@wokkil.pair.com> <20030410155449.A32215@timji.consultix-inc.com> <20030410234058.A77781@beaver.net> Message-ID: Doug Beaver writes: > can we please keep politics off the spug list? unless we're talking > about p5p? :-) Kill joy!!! Not even a smirking smiley for "join @allied_forces"? :-{ -- Michael R. Wolf All mammals learn by playing! MichaelRunningWolf@att.net From doug at beaver.net Sat Apr 12 23:12:34 2003 From: doug at beaver.net (Doug Beaver) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:WMD as I see it In-Reply-To: ; from MichaelRunningWolf@att.net on Sat, Apr 12, 2003 at 08:17:02PM -0700 References: <20030410133641.A31349@timji.consultix-inc.com> <20030410221411.GB4217@wokkil.pair.com> <20030410155449.A32215@timji.consultix-inc.com> <20030410234058.A77781@beaver.net> Message-ID: <20030413001234.A45606@beaver.net> On Sat, Apr 12, 2003 at 08:17:02PM -0700, Michael R. Wolf wrote: > Doug Beaver writes: > > > can we please keep politics off the spug list? unless we're talking > > about p5p? :-) > > Kill joy!!! > > Not even a smirking smiley for "join @allied_forces"? > :-{ i'll give you a smirking smiley when you actually come up with something clever, dude. your post was so j.v., it hurt my eyes to read it, speaking as someone who enjoys *intelligent* debate about current events on forums where it's appropriate. if you're going to club people over the head with your opinions, at least do it with a little class and style. sheesh. i don't think it's against the rules to talk about these sort of things, i just think it's dumb to waste time rehashing the same old tired arguments that each side of the fence uses. if you're going to discuss it, at least raise the level of discussion to something meaningful. and yes, i know what sarcasm is and i know what satire is. your post was neither. doug -- "Contrary to what most people say, the most dangerous animal in the world is not the lion or the tiger or even the elephant. It's a shark riding on an elephant's back, just trampling and eating everything they see." -- Jack Handey From j.palmer2 at gte.net Sat Apr 12 23:58:48 2003 From: j.palmer2 at gte.net (John Palmer) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:WMD as I see it In-Reply-To: <20030413001234.A45606@beaver.net> References: <20030410133641.A31349@timji.consultix-inc.com> <20030410221411.GB4217@wokkil.pair.com> <20030410155449.A32215@timji.consultix-inc.com> <20030410234058.A77781@beaver.net> <20030413001234.A45606@beaver.net> Message-ID: <1050209931.12485.3.camel@RainCity> On Sat, 2003-04-12 at 21:12, Doug Beaver wrote: > i'll give you a smirking smiley when you actually come up with something > clever, dude. > yes, i know what sarcasm is and i know what satire is. your post was > neither. > So, dude, why not try your delete key and spare the rest of us your policing? Inquiring minds, -John From michael at firewing.org Sun Apr 13 12:43:06 2003 From: michael at firewing.org (John Michael Mars) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:WMD as I see it In-Reply-To: <1050209931.12485.3.camel@RainCity> Message-ID: > So, dude, why not try your delete key and spare the rest of us your > policing? It's easier to use your own delete key than to tell someone else (convincingly) to use theirs. - Michael On 12 Apr 2003, John Palmer wrote: > On Sat, 2003-04-12 at 21:12, Doug Beaver wrote: > > i'll give you a smirking smiley when you actually come up with something > > clever, dude. > > > > > yes, i know what sarcasm is and i know what satire is. your post was > > neither. > > > > So, dude, why not try your delete key and spare the rest of us your > policing? > > Inquiring minds, > -John > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: www.seattleperl.org > From j.palmer2 at gte.net Sun Apr 13 14:31:28 2003 From: j.palmer2 at gte.net (John Palmer) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:WMD as I see it In-Reply-To: References: Message-ID: <1050262291.1136.0.camel@RainCity> On Sun, 2003-04-13 at 10:43, John Michael Mars wrote: > > It's easier to use your own delete key than to tell someone else > (convincingly) to use theirs. > Which ignores the fact that I'm not complaining about the thread in question - I'm reading it... From thane at fastmail.fm Mon Apr 14 12:57:25 2003 From: thane at fastmail.fm (Thane Williams) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:RSVP Message-ID: <20030414175726.0DDEF501C2@smtp.us2.messagingengine.com> I'd like a seat at the Cedars tomorrow. Thanks. From tim at consultix-inc.com Tue Apr 15 15:04:24 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:April Mtg: Perl for UNIX Users and Programmers Message-ID: <20030415130424.A19176@timji.consultix-inc.com> SPUGsters, Please let us know by 3pm 4/15 (by posting to the list) if you'd like a seat reserved for you at Cedar's before tonight's meeting. See you there! ======================================================= | Tim Maher, Ph.D. tim@timmaher.org | | JAWCAR ("Just Another White-Camel Award Recipient") | | SPUG Founder & Leader spug@seattleperl.org | | Seattle Perl Users Group www.seattleperl.org | ======================================================= April 2003 Seattle Perl Users Group Meeting ----------------------------------------------------- Theme: "Perl for UNIX Users" Speaker: Tim Maher, Consultix Time: Tuesday, April 15, 2003 7-9pm Location: SAFECO bldg, Brooklyn St. and NE 45th St. Cost: Admission is free and open to the general public. Info: http://seattleperl.org/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Tim is writing_a_book for Manning_Publications called "Minimal Perl for Shell Users and Programmers". Unlike other Perl books, this one will give the reader advanced standing for existing knowledge of UNIX shell commands and shell programming techniques, and capitalize on that to make Perl easier to learn. In this talk, Tim will feature excerpts from the upcoming book, and his associated conference presentations at Linux_Fest_Northwest, YAPC:: America::North, and The Perl Conference. He looks forward to receiving sage feedback from SPUGsters on what works and doesn't in these presentations! Topics will include: * the Five Perl One-liners all UNIX users should know * three Perl scripts UNIX users shouldn't live without * simple Perl scripts that improve on sed, grep, and awk * how the Shell's looping facilities compare to those of Perl, including o why the Shell's "while" loop is superior to its Perl counterpart o why Perl's "do/while" sucks o when to use the implicit (-n) loop, and when to roll your own o where you can use "goto" without shame o which Shell loop is missing from standard Perl, and how to use it anyway Pre- and Post- Meeting Activities --------------------------------- The pre-meeting dinner will be at the Cedars restaurant, at 50th St. and Brooklyn, in the University District, near the Safeco building where the meeting will take place. The phone number is 527-5247. If you're planning to be there, please RSVP to the list by 2pm on the meeting day with your expected arrival time (5:30-5:45pm is recommended). TO BE FAIR, from now on only those who comply with the RSVP policy (and are therefore counted in the seating reservation) will be allowed to sit at the speaker's table. -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* _____________________________________________________________ Seattle Perl Users Group Mailing List POST TO: spug-list@mail.pm.org ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list MEETINGS: 3rd Tuesdays, U-District, Seattle WA WEB PAGE: www.seattleperl.org From tim at consultix-inc.com Tue Apr 15 15:06:12 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:June meeting is 6/11, not 6/10 Message-ID: <20030415130612.B19176@timji.consultix-inc.com> SPUGsters, Just a quick not to advise you that our June meeting will be on Wednesday, 6/11, rather than the usual 3rd Tuesday of 6/17 (due to YAPC interference). Please mark this down on your calendars. -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From tim at consultix-inc.com Wed Apr 16 19:49:30 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX Message-ID: <20030416174930.A25359@timji.consultix-inc.com> SPUGsters, Seems like most people stayed home to work on their taxes last night, judging from the turnout at our April SPUG meeting 8-{ But I gave my talk anyway -- well, at least *part* of it. It took me the full two hours to cover "Perl as a Better Grep, Sed, and Awk", so I didn't delve into the other advertised topics, which were: * 5 Perl One-liners All Unix/Linux Users Should Know * 3 Perl Scripts UNIX/Linux Users Shouldn't Live Without * How Perl's Looping Facilities Compare to the Shell's I've got my own ideas about what the "5" and the "3" are, but I'm very interested to get input from you folks on your favorites! So please give some thought as to what Perl one-liners or small scripts you value for your UNIX/Linux work, and post them to the list so we can discuss them. If I like your submissions, with your permission, I'll include them in my book, and you'll get "your foot-noted". 8-} I'll start off the discussion with one of each. In the one-liner category, a command to convert MEMO.TXT (transferred from some evil OS) to memo.txt: echo MEMO.TXT | perl -wlne 'rename $_, "\L$_\E"' (It's processing input because arg-handling takes more typing.) ls *[A-Z]* | perl -wlne 'rename $_, "\L$_\E"' (to rename all files in directory) Here's a *deluxe version* with error-checking: perl -wlne 'rename $_, "\L$_\E" or warn "rename failed for $_, $!\n"' (Surprisingly, there's no warning for a missing file, but there's a missing file warning for a permission error -- at least on Linux!) In the script category, I offer one that sorts filenames by modification time, which is something find . -name 'x' | xargs ls -rdlt can't be trusted to do, because of the possibility of separate sorts for different argument sets with lots of filenames. I'll post the code samples from last night's talk on my web site soon, and announce that to the list when it happens. Here's the script UNIX SAs shouldn't live without: #! /usr/local/bin/perl -w # sort_files_by_mtime # Tim Maher, tim@teachmeperl.com # # Sorts files by mod times, using Schwartzian transform, # and prints filename and mod-time. # Gives correct answers for large collections of names, # where "find . -print | xargs ls -rdtl" cannot # NOTE: Use find or locate to provide input, or ls -d dir/*, # but *not* simply "ls dir" (dir won't be present in pathnanme, # which will trigger "invalid file" error # Sample invocations: # locate '*.c' | sort_files_by_mtime # find /local -name 'somescript' | sort_files_by_mtime # sort_files_by_mtime < /tmp/filelist $USAGE="Usage: $0 < file_list OR find ... | $0\n" ; @ARGV and die "$USAGE" ; @files= or exit 0 ; # no input is okay chomp @files ; $max=0 ; # suppress warning for ($_=0; $_ < @files; $_++) { if ($_ ne "" and -e $files[$_]) { length $files[$_] > $max and $max = length $files[$_] } else { die "$0: Invalid filename, '$files[$_]'\n" ; delete $files[$_] ; } } @files or exit 0 ; map { printf "%${max}s %s\n", $_->[0], (scalar localtime $_->[1]) } sort { $a->[1] <=> $b ->[1] } # compare m-timestamps map { [ $_ , (stat $_)[9] ] } @files ; -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From richard at richard-anderson.org Wed Apr 16 21:10:16 2003 From: richard at richard-anderson.org (Richard Anderson) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX References: <20030416174930.A25359@timji.consultix-inc.com> Message-ID: <002401c30486$85739860$321d10ac@RAnderson> Well, this example of a scriptlet scores zero on the cleverness scale, but it has been so useful to me that I'll run it up the flagpole. When I'm writing code I often find it faster to test a Perl feature rather than reading the online or printed docs (which are sometimes misleading). So I run my psh (Perl shell) scriptlet: #! /usr/bin/perl while (<>) { eval; if ($@) { print $@ } } and type in the commands that test the feature. No terminating semicolons are needed on the commands and the if statement displays any Perl error messages. Trivial, but one of my more heavily-used scriptlets. Richard Anderson richard@richard-anderson.org www.richard-anderson.org ----- Original Message ----- From: "Tim Maher" To: Sent: Wednesday, April 16, 2003 5:49 PM Subject: SPUG:Best One-Liners and Scripts for UNIX > SPUGsters, > > Seems like most people stayed home to work on their taxes last > night, judging from the turnout at our April SPUG meeting 8-{ > > But I gave my talk anyway -- well, at least *part* of it. > > It took me the full two hours to cover "Perl as a Better > Grep, Sed, and Awk", so I didn't delve into the other > advertised topics, which were: > > * 5 Perl One-liners All Unix/Linux Users Should Know > * 3 Perl Scripts UNIX/Linux Users Shouldn't Live Without > * How Perl's Looping Facilities Compare to the Shell's > > I've got my own ideas about what the "5" and the "3" are, but I'm > very interested to get input from you folks on your favorites! > > So please give some thought as to what Perl one-liners or small > scripts you value for your UNIX/Linux work, and post them to the > list so we can discuss them. If I like your submissions, with > your permission, I'll include them in my book, and you'll get > "your foot-noted". 8-} > > I'll start off the discussion with one of each. > > In the one-liner category, a command to convert MEMO.TXT (transferred > from some evil OS) to memo.txt: > > echo MEMO.TXT | perl -wlne 'rename $_, "\L$_\E"' > (It's processing input because arg-handling takes more typing.) > > ls *[A-Z]* | perl -wlne 'rename $_, "\L$_\E"' > (to rename all files in directory) > > Here's a *deluxe version* with error-checking: > perl -wlne 'rename $_, "\L$_\E" or > warn "rename failed for $_, $!\n"' > > (Surprisingly, there's no warning for a missing file, > but there's a missing file warning for a permission error > -- at least on Linux!) > > In the script category, I offer one that sorts filenames by modification > time, which is something > find . -name 'x' | xargs ls -rdlt > can't be trusted to do, because of the possibility of separate sorts for > different argument sets with lots of filenames. > > I'll post the code samples from last night's talk on my web site soon, > and announce that to the list when it happens. > > Here's the script UNIX SAs shouldn't live without: > > #! /usr/local/bin/perl -w > # sort_files_by_mtime > # Tim Maher, tim@teachmeperl.com > # > # Sorts files by mod times, using Schwartzian transform, > # and prints filename and mod-time. > # Gives correct answers for large collections of names, > # where "find . -print | xargs ls -rdtl" cannot > > # NOTE: Use find or locate to provide input, or ls -d dir/*, > # but *not* simply "ls dir" (dir won't be present in pathnanme, > # which will trigger "invalid file" error > > # Sample invocations: > # locate '*.c' | sort_files_by_mtime > # find /local -name 'somescript' | sort_files_by_mtime > # sort_files_by_mtime < /tmp/filelist > > $USAGE="Usage: $0 < file_list OR find ... | $0\n" ; > @ARGV and die "$USAGE" ; > @files= or exit 0 ; # no input is okay > chomp @files ; > > $max=0 ; # suppress warning > for ($_=0; $_ < @files; $_++) { > if ($_ ne "" and -e $files[$_]) { > length $files[$_] > $max and > $max = length $files[$_] > } > else { > die "$0: Invalid filename, '$files[$_]'\n" ; > delete $files[$_] ; > } > } > @files or exit 0 ; > > map { printf "%${max}s %s\n", $_->[0], (scalar localtime $_->[1]) } > sort { $a->[1] <=> $b ->[1] } # compare m-timestamps > map { [ $_ , (stat $_)[9] ] } @files ; > > -Tim > *------------------------------------------------------------* > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > | CEO, JAWCAR ("Just Another White Camel Award Recipient") | > | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > | Watch for my Book: "Minimal Perl for Shell Programmers" | > *------------------------------------------------------------* > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: www.seattleperl.org > > From tim at consultix-inc.com Wed Apr 16 21:28:18 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <002401c30486$85739860$321d10ac@RAnderson> References: <20030416174930.A25359@timji.consultix-inc.com> <002401c30486$85739860$321d10ac@RAnderson> Message-ID: <20030416192818.A26227@timji.consultix-inc.com> On Wed, Apr 16, 2003 at 07:10:16PM -0700, Richard Anderson wrote: > Well, this example of a scriptlet scores zero on the cleverness scale, but > it has been so useful to me that I'll run it up the flagpole. When I'm > writing code I often find it faster to test a Perl feature rather than > reading the online or printed docs (which are sometimes misleading). So I > run my psh (Perl shell) scriptlet: > > #! /usr/bin/perl > while (<>) { > eval; > if ($@) { print $@ } > } I fool around with this sometimes myself, because I have trouble remembering the crazy command names in the -d mode (X? x?) Thanks for your contribution! -Tim > > and type in the commands that test the feature. No terminating semicolons > are needed on the commands and the if statement displays any Perl error > messages. > > Trivial, but one of my more heavily-used scriptlets. > > Richard Anderson > richard@richard-anderson.org > www.richard-anderson.org > ----- Original Message ----- > From: "Tim Maher" > To: > Sent: Wednesday, April 16, 2003 5:49 PM > Subject: SPUG:Best One-Liners and Scripts for UNIX > > > > SPUGsters, > > > > Seems like most people stayed home to work on their taxes last > > night, judging from the turnout at our April SPUG meeting 8-{ > > > > But I gave my talk anyway -- well, at least *part* of it. > > > > It took me the full two hours to cover "Perl as a Better > > Grep, Sed, and Awk", so I didn't delve into the other > > advertised topics, which were: > > > > * 5 Perl One-liners All Unix/Linux Users Should Know > > * 3 Perl Scripts UNIX/Linux Users Shouldn't Live Without > > * How Perl's Looping Facilities Compare to the Shell's > > > > I've got my own ideas about what the "5" and the "3" are, but I'm > > very interested to get input from you folks on your favorites! > > > > So please give some thought as to what Perl one-liners or small > > scripts you value for your UNIX/Linux work, and post them to the > > list so we can discuss them. If I like your submissions, with > > your permission, I'll include them in my book, and you'll get > > "your foot-noted". 8-} > > > > I'll start off the discussion with one of each. > > > > In the one-liner category, a command to convert MEMO.TXT (transferred > > from some evil OS) to memo.txt: > > > > echo MEMO.TXT | perl -wlne 'rename $_, "\L$_\E"' > > (It's processing input because arg-handling takes more typing.) > > > > ls *[A-Z]* | perl -wlne 'rename $_, "\L$_\E"' > > (to rename all files in directory) > > > > Here's a *deluxe version* with error-checking: > > perl -wlne 'rename $_, "\L$_\E" or > > warn "rename failed for $_, $!\n"' > > > > (Surprisingly, there's no warning for a missing file, > > but there's a missing file warning for a permission error > > -- at least on Linux!) > > > > In the script category, I offer one that sorts filenames by modification > > time, which is something > > find . -name 'x' | xargs ls -rdlt > > can't be trusted to do, because of the possibility of separate sorts for > > different argument sets with lots of filenames. > > > > I'll post the code samples from last night's talk on my web site soon, > > and announce that to the list when it happens. > > > > Here's the script UNIX SAs shouldn't live without: > > > > #! /usr/local/bin/perl -w > > # sort_files_by_mtime > > # Tim Maher, tim@teachmeperl.com > > # > > # Sorts files by mod times, using Schwartzian transform, > > # and prints filename and mod-time. > > # Gives correct answers for large collections of names, > > # where "find . -print | xargs ls -rdtl" cannot > > > > # NOTE: Use find or locate to provide input, or ls -d dir/*, > > # but *not* simply "ls dir" (dir won't be present in pathnanme, > > # which will trigger "invalid file" error > > > > # Sample invocations: > > # locate '*.c' | sort_files_by_mtime > > # find /local -name 'somescript' | sort_files_by_mtime > > # sort_files_by_mtime < /tmp/filelist > > > > $USAGE="Usage: $0 < file_list OR find ... | $0\n" ; > > @ARGV and die "$USAGE" ; > > @files= or exit 0 ; # no input is okay > > chomp @files ; > > > > $max=0 ; # suppress warning > > for ($_=0; $_ < @files; $_++) { > > if ($_ ne "" and -e $files[$_]) { > > length $files[$_] > $max and > > $max = length $files[$_] > > } > > else { > > die "$0: Invalid filename, '$files[$_]'\n" ; > > delete $files[$_] ; > > } > > } > > @files or exit 0 ; > > > > map { printf "%${max}s %s\n", $_->[0], (scalar localtime $_->[1]) } > > sort { $a->[1] <=> $b ->[1] } # compare m-timestamps > > map { [ $_ , (stat $_)[9] ] } @files ; > > > > -Tim > > *------------------------------------------------------------* > > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > > | CEO, JAWCAR ("Just Another White Camel Award Recipient") | > > | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > > | Watch for my Book: "Minimal Perl for Shell Programmers" | > > *------------------------------------------------------------* > > _____________________________________________________________ > > Seattle Perl Users Group Mailing List > > POST TO: spug-list@mail.pm.org > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > WEB PAGE: www.seattleperl.org > > > > -- -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From spug at ifokr.org Wed Apr 16 22:44:33 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030416174930.A25359@timji.consultix-inc.com> References: <20030416174930.A25359@timji.consultix-inc.com> Message-ID: <20030417034433.GL12203@ifokr.org> > Seems like most people stayed home to work on their taxes last > night, judging from the turnout at our April SPUG meeting 8-{ I hope to make the next one. I can only attend one evening geek meeting between SAGE and SPUG or my wife would kill me. Perhaps if you changed it to be later in the month... ;-) > * 5 Perl One-liners All Unix/Linux Users Should Know Well, I tend to functionize my perl one liners, but here are some of my favorites: function forkoff { perl -we "\$SIG{HUP}='IGNORE'; fork || fork && exec @ARGV" "$@"; } A better version of 'nohup' because the process gets inherited by init and totally dissociates, meaning you can log off and ssh won't hang on you. function sp { delim=" " if [ "$1" = '-F' ] ; then shift; delim=$1; shift; fi fields=$1; shift; $PERL5 "-F$delim" -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@ } Yeah, that's much longer than one line, but it could be reduced to this if you don't want to support alternate delimeters: function sp { $PERL5 -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@ } It's a quick dirty way to say 'show me fields X,Y,Z from the source file' using perl's array slices, ala sp -F : 0,4 /etc/passwd # show username and gecos sp 1..3 /some/file # show fields 2-4 from /some/file /some/process | sp 5,6,2,4 # show fields from /some/process output function showfunc { functions | perl -e 'do { $_=<>; exit if eof } until ( /^function '$1'/ ); print; print while $_=<> and not /^function/' } Good function to show you the body of a function using perl. (For those shells that don't support 'typeset -f functionname') Of course any '-i.bak' style one liner is invaluable. > * 3 Perl Scripts UNIX/Linux Users Shouldn't Live Without #!/usr/bin/perl @list=; for (@list) { s/^> //; print "\n" unless /\S/; write; } format STDOUT = > ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $_ . To re-format (badly, but sufficiently) email text that isn't wrapped well. -- Brian Hatch Plagiarism Systems and saves Security Engineer time. http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030416/30407c0e/attachment.bin From krahnj at acm.org Thu Apr 17 03:11:43 2003 From: krahnj at acm.org (John W. Krahn) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030417034433.GL12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> Message-ID: <03041701114300.10619@perl> On Wednesday 16 April 2003 20:44, Brian Hatch wrote: > > Yeah, that's much longer than one line, but it could be reduced > to this if you don't want to support alternate delimeters: > > function sp { > $PERL5 -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@ That could be simplified to: $PERL5 -lape'$_="@F['$fields']"' $@ :-) John -- use Perl; program fulfillment From spug at ifokr.org Thu Apr 17 08:48:47 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <03041701114300.10619@perl> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <03041701114300.10619@perl> Message-ID: <20030417134847.GV12203@ifokr.org> > > function sp { > > $PERL5 -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@ > > That could be simplified to: > > $PERL5 -lape'$_="@F['$fields']"' $@ The reason for the grep was to allow laziness: sp 5..9999 /some/file so you didn't need to actually count the fields to say "everything from field #5 and therafter" and didn't get thousands of " " chars at the end of each line. Optimal? Nah. Ugly? Yeah. Works? Yeah. And this was back when I was just starting to learn perl and hadn't learned about -l yet. (I love -l) -- Brian Hatch He without humor Systems and is unarmed. Security Engineer http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030417/69c8448e/attachment.bin From spug at ifokr.org Thu Apr 17 09:07:16 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> Message-ID: <20030417140716.GW12203@ifokr.org> > > fields=$1; > > shift; > > $PERL5 "-F$delim" -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@ > > } > > I can see here how $fields gets set, in the next example > I don't see how $fields gets set, do you? Whoops - my bad. Yeah, you still need that bit of shell. function sp { fields=$1 shift; $PERL5 -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@ } -- Brian Hatch "Beep! Beep! Nipple bus! Systems and All aboard!" Security Engineer --Bree to Reegen (4 mos) http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030417/0da1c693/attachment.bin From christopher.w.cantrall at boeing.com Thu Apr 17 15:38:10 2003 From: christopher.w.cantrall at boeing.com (Cantrall, Christopher W) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX Message-ID: <04088F154165F84E89F96113157E4B61101DFA@XCH-NW-11.nw.nos.boeing.com> I occasionally copy code from perlmonks.org (there are special links to download code, but that isn't available on scratchpads). The problem is that I have my preferences set to precede all code samples with line numbers, so code (or anything formatted like code) looks like this: 001: EXTERIOR: DAGOBAH--DAY 002: 003: With Yoda strapped to his back, Luke climbs up one of the 004: many thick vines that grow in the swamp until he reaches the 005: Dagobah statistics lab. Panting heavily, he continues his 006: exercises--grepping, installing new packages, logging in as 007: root, and writing replacements for two-year-old shell 008: scripts in Python. 009: 010: YODA: 011: Code! Yes. A programmer's strength flows from code 012: maintainability. But beware of Perl. Terse syntax... more 013: than one way to do it... default variables. The dark side 014: of code maintainability are they. Easily they flow, quick to 015: join you when code you write. If once you start down the 016: dark path, forever will it dominate your destiny, consume 017: you it will. 018: 019: LUKE: 020: Is Perl better than Python? 021: 022: YODA: 023: No... no... no. Quicker, easier, more seductive. 024: 025: LUKE: 026: But how will I know why Python is better than Perl? 027: 028: YODA: 029: You will know. When your code you try to read six months 030: from now. Which isn't so bad for reading jokes, but tends to make code do funny things. Like fail to compile. So I banged out this Llama-level number stripper: #!/usr/bin/perl -w use strict; my $filename = shift @ARGV; open (FH, $filename) or die $!; my @file = ; my @out; push @out, "#!/usr/bin/perl\nuse strict;\n\n"; foreach my $line (@file) { $line =~ s/^\s*\d{3}:\s//; push @out, $line; } print @out; It's the sort of thing I love about perl: solve a quick problem in a readable, maintable way. And I don't need to add the she-bang line manually. ________________________________________ Christopher Cantrall Structural Engineer, 767 Fuselage phone: 425-342-4131 fax: 425-717-3174 M/C 0Y-12 -- 40-83 E7 Christopher.W.Cantrall@Boeing.com > -----Original Message----- > From: Tim Maher [mailto:tim@consultix-inc.com] > Sent: Wednesday, April 16, 2003 5:50 PM > To: spug-list@pm.org > Subject: SPUG:Best One-Liners and Scripts for UNIX > > > SPUGsters, > > Seems like most people stayed home to work on their taxes last > night, judging from the turnout at our April SPUG meeting 8-{ > > But I gave my talk anyway -- well, at least *part* of it. > > It took me the full two hours to cover "Perl as a Better > Grep, Sed, and Awk", so I didn't delve into the other > advertised topics, which were: > > * 5 Perl One-liners All Unix/Linux Users Should Know > * 3 Perl Scripts UNIX/Linux Users Shouldn't Live Without > * How Perl's Looping Facilities Compare to the Shell's > > I've got my own ideas about what the "5" and the "3" are, but I'm > very interested to get input from you folks on your favorites! > > So please give some thought as to what Perl one-liners or small > scripts you value for your UNIX/Linux work, and post them to the > list so we can discuss them. If I like your submissions, with > your permission, I'll include them in my book, and you'll get > "your foot-noted". 8-} From tim at consultix-inc.com Thu Apr 17 16:48:38 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <04088F154165F84E89F96113157E4B61101DFA@XCH-NW-11.nw.nos.boeing.com> References: <04088F154165F84E89F96113157E4B61101DFA@XCH-NW-11.nw.nos.boeing.com> Message-ID: <20030417144838.A29037@timji.consultix-inc.com> On Thu, Apr 17, 2003 at 01:38:10PM -0700, Cantrall, Christopher W wrote: > So I banged out this Llama-level number stripper: > > #!/usr/bin/perl -w > use strict; > > my $filename = shift @ARGV; > open (FH, $filename) or die $!; > my @file = ; > my @out; > > push @out, "#!/usr/bin/perl\nuse strict;\n\n"; > foreach my $line (@file) { > $line =~ s/^\s*\d{3}:\s//; > push @out, $line; > } > print @out; > > > It's the sort of thing I love about perl: solve a quick problem in a > readable, maintable way. And I don't need to add the she-bang line > manually. I agree! The only thing you'll have to add manually is the (all-important) -w perl invocation option your script leaves out! 8-} But dude, you're writing much more code than is necessary! You could take advantage of the implicit (-p) loop, with its implicit open(), and dispense with the array, and make it a two-liner: #!/usr/bin/perl -wp BEGIN { print "#!/usr/bin/perl -wp\nuse strict;\n\n"; } s/^\s*\d{3}:\s//; # print; # courtesy of -p option You might also want to convert spaces to tabs, if you prefer tabs in your code, using Text::Tabs::unexpand(). -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From krahnj at acm.org Thu Apr 17 17:03:11 2003 From: krahnj at acm.org (John W. Krahn) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030417134847.GV12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <03041701114300.10619@perl> <20030417134847.GV12203@ifokr.org> Message-ID: <03041715031100.20585@perl> On Thursday 17 April 2003 06:48, Brian Hatch wrote: > > > function sp { > > > $PERL5 -ape 'chomp @F; $_=join(" ",grep /./, > > > @F['$fields'])."\n"' $@ > > > > That could be simplified to: > > > > $PERL5 -lape'$_="@F['$fields']"' $@ > > The reason for the grep was to allow laziness: > > sp 5..9999 /some/file > > so you didn't need to actually count the fields to say "everything > from field #5 and therafter" and didn't get thousands of " " chars at > the end of each line. Optimal? Nah. Ugly? Yeah. Works? Yeah. Ah yes, trailing whitespace. $PERL5 -lape'($_="@F['$fields']")=~s/\s+$//' $@ :-) John -- use Perl; program fulfillment From spug at ifokr.org Thu Apr 17 17:44:12 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <03041715031100.20585@perl> References: <20030416174930.A25359@timji.consultix-inc.com> <03041701114300.10619@perl> <20030417134847.GV12203@ifokr.org> <03041715031100.20585@perl> Message-ID: <20030417224412.GL12203@ifokr.org> > Ah yes, trailing whitespace. > > $PERL5 -lape'($_="@F['$fields']")=~s/\s+$//' $@ TMTOWTDI. But yours was better. (It's always instructive to revisit stuff you wrote seven years ago and laugh at how badly you did it...) -- Brian Hatch There you have the Systems and source of your Security Engineer popularity http://www.ifokr.org/bri/ -- your absense. Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030417/9f149aa4/attachment.bin From jimfl at tensegrity.net Thu Apr 17 18:29:49 2003 From: jimfl at tensegrity.net (Jim Flanagan) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030417144838.A29037@timji.consultix-inc.com> Message-ID: On Thu, 17 Apr 2003, SPUG-list-owner wrote: > On Thu, Apr 17, 2003 at 01:38:10PM -0700, Cantrall, Christopher wrote: > > > > It's the sort of thing I love about perl: solve a quick problem in a > > readable, maintable way. And I don't need to add the she-bang line > > manually. > > But dude, you're writing much more code than is necessary! > > #!/usr/bin/perl -wp > BEGIN { print "#!/usr/bin/perl -wp\nuse strict;\n\n"; } > s/^\s*\d{3}:\s//; > # print; # courtesy of -p option I'm pretty sure Christopher mentioned something about "readable, maintainable." :^) -- ::jimfl http://jimfl.tensegrity.net mailto:jimfl%40t%65ns%65gr%69ty.n%65t From christopher.w.cantrall at boeing.com Thu Apr 17 18:53:24 2003 From: christopher.w.cantrall at boeing.com (Cantrall, Christopher W) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX Message-ID: <04088F154165F84E89F96113157E4B61101DFC@XCH-NW-11.nw.nos.boeing.com> > I agree! The only thing you'll have to add manually is the > (all-important) -w perl invocation option your script leaves > out! 8-} Whoops. > > push @out, "#!/usr/bin/perl __ -w __ \nuse strict;\n\n"; And without the she-bang line, it's a oneliner: perl -ep 's/^\s*\d{3}:\s//;' yodacode.txt > yoda.txt Hmmm, I can't get that to work. I think that I'm feeding the file in wrong. I know that this works: #!/usr/bin/perl -wp s/^\s*\d{3}:\s//; when called like so: perl decode.pl yodacode.txt > yoda.txt but I can't get the above one-liner to work in AIX. I'll fiddle with that at home. > > I'm pretty sure Christopher mentioned something about "readable, > maintainable." > > :^) True, Jim, but aside from the BEGIN block (which is pretty darn cool), the hard part of Tim's program is the regex, which is identical to mine. I guess getting rid of all of that accounting in my original program means that the mean complexity increased. :) ________________________________________ Christopher Cantrall Structural Engineer, 767 Fuselage phone: 425-342-4131 fax: 425-717-3174 M/C 0Y-12 -- 40-83 E7 Christopher.W.Cantrall@Boeing.com > -----Original Message----- > From: SPUG-list-owner [mailto:tim@consultix-inc.com] > Sent: Thursday, April 17, 2003 2:49 PM > To: Cantrall, Christopher W > Cc: spug-list@pm.org > Subject: Re: SPUG:Best One-Liners and Scripts for UNIX > > > On Thu, Apr 17, 2003 at 01:38:10PM -0700, Cantrall, > Christopher W wrote: > > So I banged out this Llama-level number stripper: > > > > #!/usr/bin/perl -w > > use strict; > > > > my $filename = shift @ARGV; > > open (FH, $filename) or die $!; > > my @file = ; > > my @out; > > > > push @out, "#!/usr/bin/perl\nuse strict;\n\n"; > > foreach my $line (@file) { > > $line =~ s/^\s*\d{3}:\s//; > > push @out, $line; > > } > > print @out; > > > > > > It's the sort of thing I love about perl: solve a quick > problem in a > > readable, maintable way. And I don't need to add the she-bang line > > manually. > > I agree! The only thing you'll have to add manually is the > (all-important) -w perl invocation option your script leaves > out! 8-} > > But dude, you're writing much more code than is necessary! > > You could take advantage of the implicit (-p) loop, with its > implicit open(), and dispense with the array, and make it a > two-liner: > > #!/usr/bin/perl -wp > BEGIN { print "#!/usr/bin/perl -wp\nuse strict;\n\n"; } > s/^\s*\d{3}:\s//; > # print; # courtesy of -p option > > You might also want to convert spaces to tabs, if you prefer > tabs in your code, using Text::Tabs::unexpand(). > > -Tim > *------------------------------------------------------------* > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > | CEO, JAWCAR ("Just Another White Camel Award Recipient") | > | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > | Watch for my Book: "Minimal Perl for Shell Programmers" | > *------------------------------------------------------------* > From tim at consultix-inc.com Thu Apr 17 19:29:40 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <04088F154165F84E89F96113157E4B61101DFC@XCH-NW-11.nw.nos.boeing.com> References: <04088F154165F84E89F96113157E4B61101DFC@XCH-NW-11.nw.nos.boeing.com> Message-ID: <20030417172940.A29483@timji.consultix-inc.com> On Thu, Apr 17, 2003 at 04:53:24PM -0700, Cantrall, Christopher W wrote: > > I agree! The only thing you'll have to add manually is the > > (all-important) -w perl invocation option your script leaves > > out! 8-} > > Whoops. > > > push @out, "#!/usr/bin/perl __ -w __ \nuse strict;\n\n"; > > And without the she-bang line, it's a oneliner: > > perl -ep 's/^\s*\d{3}:\s//;' yodacode.txt > yoda.txt > Hmmm, I can't get that to work. I think that I'm feeding the file in wrong. -ep means your program consists only of "p", which won't do much (the next token after -e is taken as the program). You need to say -pe 'code', which makes all the difference. > > > > I'm pretty sure Christopher mentioned something about "readable, > > maintainable." > > > > :^) > > True, Jim, but aside from the BEGIN block (which is pretty darn > cool), the hard part of Tim's program is the regex, which is > identical to mine. I guess getting rid of all of that accounting in > my original program means that the mean complexity increased. :) The beauty of the -n/-p option is that it lets you focus on what you're trying to achieve, instead of reinventing the boilerplate infrastructure for a program that needs to process input from files. IMHO, a one-line program that consists only of a substitution operator is much more readable and maintainable than a 10 line one that fools around with argument management, file opening, and input acquisition when all it's doing is the equivalent of a sed-command in Perl. But YMMV, because of TMTOWTDI! -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From tim at consultix-inc.com Fri Apr 18 00:42:40 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030417140716.GW12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> Message-ID: <20030417224240.A30335@timji.consultix-inc.com> On Thu, Apr 17, 2003 at 07:07:16AM -0700, Brian Hatch wrote: > > > function sp { > fields=$1 > shift; > $PERL5 -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@ > } > Brian Hatch "Beep! Beep! Nipple bus! Ouch! That's too complicated for my "Minimal Perl" tastes. How about the following as a one-liner to type directly to the shell, perl -wlna -e 'print "@F[3,1,2]"' file or the following as a more civilized scriptified version: #! /usr/bin/perl -wlna BEGIN { # first argument contains comma-separated field numbers # order of numbers determines order of printing fields $fields = shift; @fields = $fields =~ /\d+/g or die "Usage: $0 '2,1,3' [ file ... ]"; # The more obvious parsing solution passes non-digits - BAD! # @fields=split /,/ , $fields or } @F or next; # skip blank lines # User should specify from #1 unshift @F, "(No zeroth field! first is #1)"; print "@F[ @fields ]"; -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From spug at ifokr.org Fri Apr 18 08:33:02 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030417224240.A30335@timji.consultix-inc.com> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> Message-ID: <20030418133302.GX12203@ifokr.org> > Ouch! That's too complicated for my "Minimal Perl" tastes. I just gave you my starting point - of course we can play with things. > How about the following as a one-liner to type directly to the shell, > perl -wlna -e 'print "@F[3,1,2]"' file I use perl one liners on the command line all the time. But when I use one too much, then I put it in a function so I don't need to any more. That's the whole point. > unshift @F, "(No zeroth field! first is #1)"; Are you nuts? That was the whole point of using perl! Of course the first field should be field #0. Anything else is unperlish. I also wanted the use of the '..' operator - you're not going to take that away, are you?. -- Brian Hatch Language, it's a virus. Systems and Security Engineer http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030418/0d849fbe/attachment.bin From tim at consultix-inc.com Fri Apr 18 11:57:18 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030418133302.GX12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> Message-ID: <20030418095718.A32078@timji.consultix-inc.com> On Fri, Apr 18, 2003 at 06:33:02AM -0700, Brian Hatch wrote: > > > > Ouch! That's too complicated for my "Minimal Perl" tastes. > > I just gave you my starting point - of course we can > play with things. I'm not criticizing, just exploring simpler approaches. > > How about the following as a one-liner to type directly to the shell, > > perl -wlna -e 'print "@F[3,1,2]"' file > > I use perl one liners on the command line all the time. But > when I use one too much, then I put it in a function so I don't > need to any more. That's the whole point. Agreed. > > unshift @F, "(No zeroth field! first is #1)"; > > Are you nuts? That was the whole point of using perl! Of course > the first field should be field #0. Anything else is unperlish. Huh??? My point was that it's more *Human-ish* to let the user specify the first field as field #1 (like Awk does), regardless of what Perl uses internally. TMTOWTDI! > I also wanted the use of the '..' operator - you're not going > to take that away, are you?. > > Brian Hatch Language, it's a virus. I'm not trying to take *anything* away from you, just improvising alternative approaches that bring out other trade-offs, that people might find interesting. Your solution (which I can't see right now, but I think I remember the essentials) had the benefit of being pre-processed by a shell, so the dots in 1..2 would be seen in the initial parsing of the Perl program. With the pure-perl approach I've taken, I believe an eval would be required to handle the range specifier (since it resides in a variable), and I decided to draw the line there. -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From tim at consultix-inc.com Fri Apr 18 11:58:15 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX Message-ID: <20030418095815.B32078@timji.consultix-inc.com> On Fri, Apr 18, 2003 at 06:33:02AM -0700, Brian Hatch wrote: > > > > Ouch! That's too complicated for my "Minimal Perl" tastes. > > I just gave you my starting point - of course we can > play with things. I'm not criticizing, just exploring simpler approaches. > > How about the following as a one-liner to type directly to the shell, > > perl -wlna -e 'print "@F[3,1,2]"' file > > I use perl one liners on the command line all the time. But > when I use one too much, then I put it in a function so I don't > need to any more. That's the whole point. Agreed. > > unshift @F, "(No zeroth field! first is #1)"; > > Are you nuts? That was the whole point of using perl! Of course > the first field should be field #0. Anything else is unperlish. Huh??? My point was that it's more *Human-ish* to let the user specify the first field as field #1 (like Awk does), regardless of what Perl uses internally. TMTOWTDI! > I also wanted the use of the '..' operator - you're not going > to take that away, are you?. > > Brian Hatch Language, it's a virus. I'm not trying to take *anything* away from you, just improvising alternative approaches that bring out other trade-offs, that people might find interesting. Your solution (which I can't see right now, but I think I remember the essentials) had the benefit of being pre-processed by a shell, so the dots in 1..2 would be seen in the initial parsing of the Perl program. With the pure-perl approach I've taken, I believe an eval would be required to handle the range specifier (since it resides in a variable), and I decided to draw the line there. -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* ----- End forwarded message ----- -- -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From spug at ifokr.org Fri Apr 18 12:05:12 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030418095718.A32078@timji.consultix-inc.com> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030418095718.A32078@timji.consultix-inc.com> Message-ID: <20030418170512.GC12203@ifokr.org> > > > unshift @F, "(No zeroth field! first is #1)"; > > > > Are you nuts? That was the whole point of using perl! Of course > > the first field should be field #0. Anything else is unperlish. > > Huh??? Out of curiousity, what languages are zero based vs one based? Perl is zero based (unless you use '$[ = 1') Zero based: C, C++, Perl, Python[1] ... One based: Fortran, awk, Perl[2] [1] IIRC [2] If you use '$[ = 1', but don't do that. -- Brian Hatch Never take life seriously. Systems and Nobody gets out alive, Security Engineer anyway. http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030418/9980ab6a/attachment.bin From david.dyck at fluke.com Fri Apr 18 12:12:27 2003 From: david.dyck at fluke.com (David Dyck) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030418170512.GC12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030418095718.A32078@timji.consultix-inc.com> <20030418170512.GC12203@ifokr.org> Message-ID: On Fri, 18 Apr 2003 at 10:05 -0700, Brian Hatch wrote: > Out of curiousity, what languages are zero based vs one based? > Perl is zero based (unless you use '$[ = 1') > > Zero based: > C, C++, Perl, Python[1] ... bash, ksh > One based: > Fortran, awk, Perl[2] csh english (first person in line, not the zero'th, right) > [1] IIRC > > [2] If you use '$[ = 1', but don't do that. From tnight at pobox.com Fri Apr 18 12:13:32 2003 From: tnight at pobox.com (Terry Nightingale) Date: Mon Aug 2 21:36:55 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030418170512.GC12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030418095718.A32078@timji.consultix-inc.com> <20030418170512.GC12203@ifokr.org> Message-ID: <3EA0323C.2040004@pobox.com> BASIC and its progeny (Business BASIC, VB, VBA, VBScript, etc.) are also one-based. JavaScript, however, is zero-based like Java. Go figure. Brian Hatch wrote: > >>>>unshift @F, "(No zeroth field! first is #1)"; >>> >>>Are you nuts? That was the whole point of using perl! Of course >>>the first field should be field #0. Anything else is unperlish. >> >>Huh??? > > > Out of curiousity, what languages are zero based vs one based? > Perl is zero based (unless you use '$[ = 1') > > Zero based: > C, C++, Perl, Python[1] ... > > One based: > Fortran, awk, Perl[2] > > > [1] IIRC > > [2] If you use '$[ = 1', but don't do that. > > > > -- > Brian Hatch Never take life seriously. > Systems and Nobody gets out alive, > Security Engineer anyway. > http://www.ifokr.org/bri/ > > Every message PGP signed -- Terry Nightingale Web Developer, Philosopher, Geek "In theory, there is no difference between theory and practice. But, in practice, there is." -- Jan L.A. van de Snepscheut -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3411 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.pm.org/pipermail/spug-list/attachments/20030418/fa906772/smime.bin From spug at ifokr.org Fri Apr 18 12:17:35 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030418095718.A32078@timji.consultix-inc.com> <20030418170512.GC12203@ifokr.org> Message-ID: <20030418171735.GF12203@ifokr.org> > english (first person in line, not the zero'th, right) No, that'd be American. In English, the people are in a queue. I actually have been caught by zero-based thinking in the past. I once was coding non stop for about 80 hours, and knew when I woke up that I'd have 4 things to do. I woke the next afternoon, tried to remember the things, and as I said them out loud to myself ticked off a finger. I held up 4 fingers by the end, and couldn't remember what the last thing I needed to remember was, because looking at 4 fingers I saw the number '3'. -- Brian Hatch I hate to stand Systems and between a man Security Engineer and his affairs. http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030418/d45dfb6d/attachment.bin From creede at penguinsinthenight.com Fri Apr 18 12:27:56 2003 From: creede at penguinsinthenight.com (Creede Lambard) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030418170512.GC12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030418095718.A32078@timji.consultix-inc.com> <20030418170512.GC12203@ifokr.org> Message-ID: <1050686876.17459.108.camel@svetlana.penguinsinthenight.com> From what little Basic I can remember, it's one based. However in Visual Basic at least you can use the OPTION BASE keyword to change the "start" of the array if you have a particular reason for doing so. On Fri, 2003-04-18 at 10:05, Brian Hatch wrote: > > > > unshift @F, "(No zeroth field! first is #1)"; > > > > > > Are you nuts? That was the whole point of using perl! Of course > > > the first field should be field #0. Anything else is unperlish. > > > > Huh??? > > Out of curiousity, what languages are zero based vs one based? > Perl is zero based (unless you use '$[ = 1') > > Zero based: > C, C++, Perl, Python[1] ... > > One based: > Fortran, awk, Perl[2] > > > [1] IIRC > > [2] If you use '$[ = 1', but don't do that. > > > > -- > Brian Hatch Never take life seriously. > Systems and Nobody gets out alive, > Security Engineer anyway. > http://www.ifokr.org/bri/ > > Every message PGP signed -- Creede Lambard -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://mail.pm.org/pipermail/spug-list/attachments/20030418/e36bf01a/attachment.bin From scott+spug at mail.dsab.rresearch.com Fri Apr 18 16:45:15 2003 From: scott+spug at mail.dsab.rresearch.com (Scott Blachowicz) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Re: Best One-Liners and Scripts for UNIX In-Reply-To: <20030418170512.GC12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030418095718.A32078@timji.consultix-inc.com> <20030418170512.GC12203@ifokr.org> Message-ID: <200304182145.h3ILjLF10450@mail.pm.org> Brian Hatch wrote: > Out of curiousity, what languages are zero based vs one based? > Perl is zero based (unless you use '$[ =3D 1') > > Zero based: > C, C++, Perl, Python[1] ... > > One based: > Fortran, awk, Perl[2] Also, IIRC PASCAL is one-based. (I'd imagine that other languages would be doing the same thing...e.g. Modula? Ada?) Scott From tim at consultix-inc.com Sat Apr 19 12:37:13 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030418133302.GX12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> Message-ID: <20030419103713.A3251@timji.consultix-inc.com> On Fri, Apr 18, 2003 at 06:33:02AM -0700, Brian Hatch wrote: > > > Ouch! That's too complicated for my "Minimal Perl" tastes. > > I also wanted the use of the '..' operator - you're not going > to take that away, are you?. > -- > Brian Hatch Language, it's a virus. Here's a version that honors the range operator. #! /usr/bin/perl -wlna # show_fields2c # (C) 2003, Tim Maher www.TeachMePerl.Com BEGIN { # first argument contains comma-separated field numbers # order of numbers determines order of printing fields ($fields = shift) =~ /^[\d,.]+$/g or die "Usage: fields='2,1,3,4..7' $0 [ file ... ]"; @fields = eval " ( $fields ) "; # 5,2..4 => 5,2,3,4 } @F or next; # skip blank lines # Let user specify from #1 unshift @F, "(No zeroth field! first is #1)"; print "@F[ @fields ]"; -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From tim at consultix-inc.com Sat Apr 19 14:44:02 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030419103713.A3251@timji.consultix-inc.com> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> Message-ID: <20030419124402.A3576@timji.consultix-inc.com> On Sat, Apr 19, 2003 at 10:37:13AM -0700, Tim Maher wrote: This version has the corrected Usage messasge (the compiler missed that mistake! 8-}) -Tim > > BEGIN { > # first argument contains comma-separated field numbers > # order of numbers determines order of printing fields > ($fields = shift) =~ /^[\d,.]+$/g or die "Usage: fields='2,1,3,4..7' $0 [ file ... ]"; #BAD die "Usage: $0 '2,1,3,4..7' [ file ... ]"; #GOOD > @fields = eval " ( $fields ) "; # 5,2..4 => 5,2,3,4 > } > > @F or next; # skip blank lines > # Let user specify from #1 > unshift @F, "(No zeroth field! first is #1)"; > print "@F[ @fields ]"; > > > -Tim > *------------------------------------------------------------* > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > | CEO, JAWCAR ("Just Another White Camel Award Recipient") | > | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > | Watch for my Book: "Minimal Perl for Shell Programmers" | > *------------------------------------------------------------* > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: www.seattleperl.org -- -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From bob at hiltners.com Sat Apr 19 15:22:59 2003 From: bob at hiltners.com (Bob Hiltner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> Message-ID: <001601c306b1$789589f0$0200a8c0@computer> Seeing all the one-liners (not this post particularly) brings to mind one of the great things about PERL. You don't need code obfuscation utilities for IP protection. It's done automatically at the source code level! ;^) What's the other way to say it? Write Once, Read Never? On a more serious note... that is one of the things that does make me shy away from getting into perl in a serious way... too much magic. This stuff that (perhaps) makes sense to the initiated and the high priests is like reading binaries to the casual perler. I've been doing more .Net stuff for a while, and I feel the understandibility of perl quickly slipping away when I (try to) read stuff like this. I don't see the same issues at all when I get away from, say, C for a while. Is that just the idioms of the language? There's plenty of cryptic stuff available in C too, but I don't see it much in real code. So what's the balance? One can be very efficient in use of precious memory at the expense of the sucker who has to follow the code, or one can write verbose cobol, and the follower can settle in for reading a nice long bedtime novel. So the question is, if writing clear and readable perl is possible, which I believe it is, is it just my perception that the idioms are toward opacity over readibility? Isn't that a bit of a shame? How do you get to the inherent coolness of the language without all the unreadable magic? It might just be me. I tend to have the same problem with regexes, which I think are the coolest thing going. If you don't use em for a while, it's a bit of retraining each time. It'd be nice to have that kind of power with some better readibility. -Bob ----- Original Message ----- From: "SPUG-list-owner" To: "Brian Hatch" Cc: "Tim Maher" ; "David Dyck" ; Sent: Saturday, April 19, 2003 10:37 AM Subject: Re: SPUG:Best One-Liners and Scripts for UNIX > On Fri, Apr 18, 2003 at 06:33:02AM -0700, Brian Hatch wrote: > > > > > Ouch! That's too complicated for my "Minimal Perl" tastes. > > > > > > I also wanted the use of the '..' operator - you're not going > > to take that away, are you?. > > -- > > Brian Hatch Language, it's a virus. > > Here's a version that honors the range operator. > > #! /usr/bin/perl -wlna > # show_fields2c > # (C) 2003, Tim Maher www.TeachMePerl.Com > > BEGIN { > # first argument contains comma-separated field numbers > # order of numbers determines order of printing fields > ($fields = shift) =~ /^[\d,.]+$/g or > die "Usage: fields='2,1,3,4..7' $0 [ file ... ]"; > @fields = eval " ( $fields ) "; # 5,2..4 => 5,2,3,4 > } > > @F or next; # skip blank lines > # Let user specify from #1 > unshift @F, "(No zeroth field! first is #1)"; > print "@F[ @fields ]"; From richard at richard-anderson.org Sat Apr 19 20:11:40 2003 From: richard at richard-anderson.org (Richard Anderson) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> Message-ID: <001401c306d9$d34c78e0$b440fea9@RAnderson> I've avoided commenting on the "minimal keystrokes" style of coding that we've seen examples of, but Bob's statement that "I feel the understandability of perl quickly slipping away when I (try to) read stuff like this" has brought me out of the woodwork. My view is that fluent Perl takes advantage of the Perl idioms that enhance cohesion and readability and avoids Perl idioms that obfuscate for the sake of producing terse code. An example of this is the grep function. Any code that uses grep can be rewritten more verbosely as a foreach loop. However, grep enhances readability because when the reader sees grep he knows the code is selecting members from a list, whereas the loop is less immediately obvious. Grep has more cohesion than a loop because its function is limited to selecting members from a list. Compressing code using Perl's convenience features can (and often does) go too far. When I find myself wondering how fancy to get with some Perl feature, I ask myself "Would an intermediate Perl programmer find the resulting code to be clear and readable?" If the answer is anything but an obvious yes, I (usually) resist temptation and write the code using the simple, "unclever" style. Writing clear, readable code that has high cohesion and low coupling is hard work. I admit it is fun to play with some of Perl's obscurities and I enjoy reading the Obfuscated Perl contest winners. Code that is posted to a discussion list shouldn't have to be of the same quality as production (or even CPAN) code. I hope that Bob and others are not assuming that there is anything about Perl that leads people to write bad code - this is a function of the programmer, not the language. (However, if anyone wants to slam awk or shell scripting as being inferior languages, I'll be right behind you.) Richard Anderson richard@richard-anderson.org www.richard-anderson.org ----- Original Message ----- From: "Bob Hiltner" To: Sent: Saturday, April 19, 2003 1:22 PM Subject: Re: SPUG:Best One-Liners and Scripts for UNIX > Seeing all the one-liners (not this post particularly) brings to mind one of > the great things about PERL. You don't need code obfuscation utilities for > IP protection. It's done automatically at the source code level! ;^) > What's the other way to say it? Write Once, Read Never? > > On a more serious note... that is one of the things that does make me shy > away from getting into perl in a serious way... too much magic. This stuff > that (perhaps) makes sense to the initiated and the high priests is like > reading binaries to the casual perler. I've been doing more .Net stuff for > a while, and I feel the understandibility of perl quickly slipping away when > I (try to) read stuff like this. I don't see the same issues at all when I > get away from, say, C for a while. Is that just the idioms of the language? > There's plenty of cryptic stuff available in C too, but I don't see it much > in real code. > > So what's the balance? One can be very efficient in use of precious memory > at the expense of the sucker who has to follow the code, or one can write > verbose cobol, and the follower can settle in for reading a nice long > bedtime novel. So the question is, if writing clear and readable perl is > possible, which I believe it is, is it just my perception that the idioms > are toward opacity over readibility? Isn't that a bit of a shame? How do > you get to the inherent coolness of the language without all the unreadable > magic? > > It might just be me. I tend to have the same problem with regexes, which I > think are the coolest thing going. If you don't use em for a while, it's a > bit of retraining each time. It'd be nice to have that kind of power with > some better readibility. > > -Bob > > ----- Original Message ----- > From: "SPUG-list-owner" > To: "Brian Hatch" > Cc: "Tim Maher" ; "David Dyck" > ; > Sent: Saturday, April 19, 2003 10:37 AM > Subject: Re: SPUG:Best One-Liners and Scripts for UNIX > > > > On Fri, Apr 18, 2003 at 06:33:02AM -0700, Brian Hatch wrote: > > > > > > > Ouch! That's too complicated for my "Minimal Perl" tastes. > > > > > > > > > > I also wanted the use of the '..' operator - you're not going > > > to take that away, are you?. > > > -- > > > Brian Hatch Language, it's a virus. > > > > Here's a version that honors the range operator. > > > > #! /usr/bin/perl -wlna > > # show_fields2c > > # (C) 2003, Tim Maher www.TeachMePerl.Com > > > > BEGIN { > > # first argument contains comma-separated field numbers > > # order of numbers determines order of printing fields > > ($fields = shift) =~ /^[\d,.]+$/g or > > die "Usage: fields='2,1,3,4..7' $0 [ file ... ]"; > > @fields = eval " ( $fields ) "; # 5,2..4 => 5,2,3,4 > > } > > > > @F or next; # skip blank lines > > # Let user specify from #1 > > unshift @F, "(No zeroth field! first is #1)"; > > print "@F[ @fields ]"; > > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: www.seattleperl.org > > From spug at ifokr.org Sat Apr 19 20:54:23 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) In-Reply-To: <001401c306d9$d34c78e0$b440fea9@RAnderson> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <001401c306d9$d34c78e0$b440fea9@RAnderson> Message-ID: <20030420015423.GN12203@ifokr.org> > My view is that fluent Perl takes advantage of the Perl idioms that enhance > cohesion and readability and avoids Perl idioms that obfuscate for the sake > of producing terse code. An example of this is the grep function. Any code > that uses grep can be rewritten more verbosely as a foreach loop. However, > grep enhances readability because when the reader sees grep he knows the > code is selecting members from a list, whereas the loop is less immediately > obvious. Grep has more cohesion than a loop because its function is limited > to selecting members from a list. Well, not always: grep { s/(\d+)/ $1 * 2 /e } @list; That'll take the first string of numbers in each element of @list (perhaps lines from a file) and double the number. It's actually modifying @list, not just selecting members. Is more readable than the following? for ( @list ) { s/(\d+)/ $1 * 2 /e; } Well, the grep one is cleaner to me - less lines to read. Others may dissagree, and I wouldn't include it when teaching someone for the first time how to do that. -- Brian Hatch "I'm thinking .. pastels!" Systems and Security Engineer http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030419/b6f5f200/attachment.bin From tim at consultix-inc.com Sun Apr 20 13:06:20 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <001601c306b1$789589f0$0200a8c0@computer> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> Message-ID: <20030420110620.A6470@timji.consultix-inc.com> On Sat, Apr 19, 2003 at 01:22:59PM -0700, Bob Hiltner wrote: > Seeing all the one-liners (not this post particularly) brings to > mind one of the great things about PERL. You don't need code > obfuscation utilities for IP protection. It's done automatically at > the source code level! ;^) What's the other way to say it? Write > Once, Read Never? Although I admit that Perl can be written inscrutably, to a degree that most other languages can only *dream* about, IMHO the majority of the posts to our list on this subject have been fairly lucid, rather than obscure. The principal subtlety has been the usual one, where there's lots happening with regard to $_, although it never actually makes an appearance. That's perfectly acceptable, IMHO, in small scripts like these where the global nature of that variable isn't likely to lead to "unintended clobberation". (After all, we're not aiming to make these programs readable by Cobol programmers!) There have been a few rather dense and terse one-liners featuring somewhat mysterious map/grep manipulations, however, that I had to stare at for too long to comprehend; but that's one of the trade-offs programmers are willing to make sometimes to force some significant data processing into one-line versions, which might never be intended for other eyes. I was glad to see that most postings also refrained from needless stylistic variations, like the "backwards" phrasings that some cherish but teachers like myself tend to eschew, such as "print if $true". I certainly don't want to start a religious war on this issue, but it triples the amount of Perl knowledge one must have to process this stuff, given that the syntax is not just backwards, it's totally different from the more prosaic and classical approach: "if ($true) { print }". Why is this triply rather than doubly complex? Because if you decide to add something new to the backwards form, you have to change the syntax to get a block in there, using do {} or some other creative solution, as in do { print; $i++ } if $true; And don't get me started on the infinitely lame do-while, which can't even process flow-control requests on its own without a while(){} wrapper to 'proxy' them. This is the kind of needless additional complexity that I like to avoid in my work, and my teaching, and that I discarded from the language when crafting my "Minimal Perl" dialect (coming to a bookstore near you this summer!). > On a more serious note... that is one of the things that does make me shy > away from getting into perl in a serious way... too much magic. This stuff > that (perhaps) makes sense to the initiated and the high priests is like > reading binaries to the casual perler. I always wonder what people are specifically talking about when they see "magic" in the kind of code we've been slinging around here. Is it magic that perl "-n" gives you a free loop? If so, is it also magic that "grep -i" ignores case, or "sed 's///g'" does multiple substitutions? Not in my book. There's plenty of "magical" (surprising and automatic) activity in Perl, but I don't recall seeing any of it here. There was one code sample posted early on in this thread that spent about 7 lines to implement the generic input reading loop that -n gives you for free; I followed up with a one-line version of that part, that showed it for what it really was, a Perl implementation of a simple sed editing command. Is this magic? Not in my book (if you'll pardon the pun); instead, it's just a worthwhile simplification that lets the reader focus on the data processing task, instead of having to wade through boilerplate infrastructure that has already been factored out by The Larry and memorialized in "-n". As a case of what most of us might call "magic" in Perl, but I'd perhaps call "tomfoolery" instead, "eof()" and "eof" do very different things, as do "use Abc()" and "use Abc". This is the kind of thing that I personally find very reprehensible in Perl, because programmers are led by other aspects of the language to believe that parentheses around argument lists are optional, and without any intrinsic meaning of their own. That's "bad magic", IMHO. And of course there's "autovivification" as another example of magic, but in Perl's defense I'd say it usually does what you meant it to anyway, and in any case you can skirt the issue by initializing on your own the objects it would create. > I've been doing more .Net stuff for a while, and I feel the > understandability of perl quickly slipping away when I (try to) read > stuff like this. I don't see the same issues at all when I get away > from, say, C for a while. Is that just the idioms of the language? Raw C provides no shortcuts, so one must always code all the routine data processing minutiae (unless you extend the language with macros) that we're allowed to invoke through invocation options like -n in Perl. Sure, that makes it more readable, in the sense that every tiny detail is spelled out, but IMHO that also makes it less comprehendible, because it's too easy to miss the view of the trees for that of the forest. > It might just be me. I tend to have the same problem with regexes, > which I think are the coolest thing going. If you don't use em for a > while, it's a bit of retraining each time. It'd be nice to have that > kind of power with some better readability. > > -Bob I know what you mean about regexes, and caught myself just yesterday staring at an extremely simple expression that wouldn't match the comments it was supposed to: s/^(.*)\b(#.*)$/ The problem of course is that \b does not mean a "word boundary" in any English language sense of "word", so this pattern would not match " # comment" but instead only strings like "ABC# comment" (where the C qualifies as a character of the opposite kind to # with respect to the [a-zA-Z_] set). Personally, I find regexes harder to debug than anything else in Perl, and I would very much like to get access to a debugger that doesn't require a GUI to work (I know there are Perl IDE's out there, but I'm a VI in an xterm kind of guy, in part due to my set of "vi-abbreviations" that prevent me from typing too much). But it's not just you, there are lots of people who don't like the way Perl programs look. And I was one of them, in my early days with the language. In my case, after realizing that some Perl features were really shortcuts for processing idioms I knew from other parts of UNIX made it all click for me (like -a for Awkish behavior, -i for sed-ish, but including the all-important file-altering capability that sed left out, etc.) For other aspects of Perl coding, like backwards conditionals and arcane uses of map, I just include the parts I like and avoid the others, and I'm happy with the custom Perl dialect I use. And I know from teaching it to UNIX programmers for many years that others with my kind of background are happy with it too. Perl's a huge language, with more diversity of expression than any of its peers, so everybody should be able to find a dialect within it that suits them. I can generally tell from reading the programs of my students what languages they've learned earlier. For example, using for ($i=0; $i<@ARGV; $i++){ print "$ARGV[$i]\n";} to print the script's arguments identifies a C, C++, or Java programmer (all from the C-school), who's reluctant to trust Perl not to run off the end of the array and crash, and foreach (@ARGV){ print "$_\n";} is more characteristic of shell programmers, who are perfectly happy to trust Perl to do the right thing. Happy Easter, everybody! Eat plenty of chocolate. . . -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From spug at ifokr.org Sun Apr 20 13:55:20 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030420110620.A6470@timji.consultix-inc.com> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <20030420110620.A6470@timji.consultix-inc.com> Message-ID: <20030420185520.GU12203@ifokr.org> > I was glad to see that most postings also refrained from needless > stylistic variations, like the "backwards" phrasings that some > cherish but teachers like myself tend to eschew, such as "print > if $true". I frequently use 'print if $true' style programming when it makes sense. First, it keeps code more concise because you don't span lines. Second, but more important, is that it can be used to write perl code that more closely maps with our thought processes themselves: do_something if i_should do_something unless i_shouldnt follow my primary language - english - very well. However this is best used when the default or desired thing is on the left. die if something_very_unusual_happened is bad form, instead you should stick to if something_very_unusual_happened { die } or something_very_unusualy_happened and die These keep the important things on the left, so as you skim the code, everything is in the same place. Similarly print stuff_to_file if $log_everything_verbosely makes more sense - you can see that a print is the stuff we really want to do, except in rare cases. -- Brian Hatch "The future reveals Systems and itself only reluctantly" Security Engineer http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030420/b0e156b3/attachment.bin From kahn at cpan.org Sun Apr 20 14:06:04 2003 From: kahn at cpan.org (Jeremy Kahn) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) In-Reply-To: <20030420015423.GN12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <001401c306d9$d34c78e0$b440fea9@RAnderson> <20030420015423.GN12203@ifokr.org> Message-ID: <3EA2EF9C.4050501@cpan.org> Brian Hatch wrote: >>Grep has more cohesion than a loop because its function is limited >>to selecting members from a list. >> >> >Well, not always: > > grep { s/(\d+)/ $1 * 2 /e } @list; > >That'll take the first string of numbers in each element of @list >(perhaps lines from a file) and double the number. It's actually >modifying @list, not just selecting members. > >Is more readable than the following? > > for ( @list ) { > s/(\d+)/ $1 * 2 /e; > } > >Well, the grep one is cleaner to me - less lines to read. > My take on this is that just because you *can* use 'grep' in place of 'for' doesn't mean you *should*. If the goal is to put it on one line, do this: for (@list) { s/(\d+)/ $1 * 2/e }; # semicolon because it clarifies that I think of this as 1 statement If the goal is to put the list on the right, use the wacky postconditions that Tim hates (you can leave the braces out if you like): { s/(\d+)/ $1 * 2/e } for (@list); >Others may dissagree, and I wouldn't include it when teaching someone for the >first time how to do that. > > IMO, grep should really be reserved for searching through a list and picking out certain elements. The "side effect" of changing the list is black magic that is unexpected and scary. My $0.02, Jeremy From spug at ifokr.org Sun Apr 20 15:19:36 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) In-Reply-To: <3EA2EF9C.4050501@cpan.org> References: <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <001401c306d9$d34c78e0$b440fea9@RAnderson> <20030420015423.GN12203@ifokr.org> <3EA2EF9C.4050501@cpan.org> Message-ID: <20030420201936.GV12203@ifokr.org> > > grep { s/(\d+)/ $1 * 2 /e } @list; ... > >Well, the grep one is cleaner to me - less lines to read. > My take on this is that just because you *can* use 'grep' in place of > 'for' doesn't mean you *should*. > > If the goal is to put it on one line, do this: > > for (@list) { s/(\d+)/ $1 * 2/e }; # semicolon because it clarifies > that I think of this as 1 statement Hmmn. Still ugly. > If the goal is to put the list on the right, use the wacky > postconditions that Tim hates (you can leave the > braces out if you like): > > { s/(\d+)/ $1 * 2/e } for (@list); Actually, I like this much better than my grep. It all falls back to my "translate perl into english" theory. Let's see the translations: grep { s/(\d+)/ $1 * 2 /e } @list; --> substitute 2*the number for all elements of @list (only means this if you know 'grep's modification of list elements in perl, which I'll admit is not frequently the case.) for (@list) { s/(\d+)/ $1 * 2/e }; # semicolon because it clarifies --> For all elements of @list, substitute 2* the number (again, you need to know that for is magic in that you are modifying the array directly too, but this is more common knowledge.) and cart-before-the-horse style: { s/(\d+)/ $1 * 2/e } for (@list); --> substitute 2* the number for all elements of @list Notice that the grep and the second for loop translate the same. The loop more closely resembles how we'd say it. I like to say 'what to do', and what' we're doing is modifying strings to double numbers within them. > IMO, grep should really be reserved for searching through a list and > picking out certain elements. The "side effect" of changing the list is > black magic that is unexpected and scary. I'd argue it's not black magic. Nothing in 'for' explicitly says you can modify the list directly. C coders using perl usually do the following first: for ( $count=0; $count>@list; $count++ ) { $list[$count] =~ s/blahblah/ } instead of for ( @list ) { s/blahblah/ } Both for and grep use magic unavailable in other languages. It's all a matter of which magic you have forgotten is magical. To a C programmer, the list form of 'for' is magic. To you it's normal. To me grep is normal. To many, horrible abuses of 'map' is standard, to me it still doesn't come as naturally. -- Brian Hatch "Need new body." -- Bree Systems and "No. Like your body. Just Security Engineer need to apply appropriate http://www.ifokr.org/bri/ patches." -- Bri Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030420/4759d55f/attachment.bin From tim at consultix-inc.com Sun Apr 20 15:47:31 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030420185520.GU12203@ifokr.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <20030420110620.A6470@timji.consultix-inc.com> <20030420185520.GU12203@ifokr.org> Message-ID: <20030420134731.A6707@timji.consultix-inc.com> On Sun, Apr 20, 2003 at 11:55:20AM -0700, Brian Hatch wrote: > > However this is best used when the default or desired thing > is on the left. > > die if something_very_unusual_happened > > is bad form, instead you should stick to > > if something_very_unusual_happened { > die I agree completely, and seeing lots of violations of this principle is one of the reasons I generally counsel against the backwards style. I've often wasted time reading and trying to comprehend a large chunk of complicated code only to see "if $leapyear" at the end! 8-} -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From richard at richard-anderson.org Sun Apr 20 23:32:17 2003 From: richard at richard-anderson.org (Richard Anderson) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <001401c306d9$d34c78e0$b440fea9@RAnderson> <20030420015423.GN12203@ifokr.org> Message-ID: <008a01c307bf$bd4e0220$b440fea9@RAnderson> This use of grep exploits a lesser-known side effect of the function and bypasses it's main purpose, which is to select elements of a list. If you want to apply a transform to every element of a list, Perl provides the map function: map { $_ =~ s/(\d+)/$1 * 2/e } @list; or, preserving the input @list: @doubled = map { ($x = $_) =~ s/(\d+)/$1 * 2/e; $x; } @list; When I read Perl code and encounter map, I immediately recognize that the code is applying a transform to the elements of a list. This "natural" style usually takes more lines of code than the "minimal keystrokes" style, but is less bug-prone and more maintainable. Richard Anderson richard@richard-anderson.org www.richard-anderson.org ----- Original Message ----- From: "Brian Hatch" To: "Richard Anderson" Cc: "Bob Hiltner" ; Sent: Saturday, April 19, 2003 6:54 PM Subject: Re: SPUG: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) > My view is that fluent Perl takes advantage of the Perl idioms that enhance > cohesion and readability and avoids Perl idioms that obfuscate for the sake > of producing terse code. An example of this is the grep function. Any code > that uses grep can be rewritten more verbosely as a foreach loop. However, > grep enhances readability because when the reader sees grep he knows the > code is selecting members from a list, whereas the loop is less immediately > obvious. Grep has more cohesion than a loop because its function is limited > to selecting members from a list. Well, not always: grep { s/(\d+)/ $1 * 2 /e } @list; That'll take the first string of numbers in each element of @list (perhaps lines from a file) and double the number. It's actually modifying @list, not just selecting members. Is more readable than the following? for ( @list ) { s/(\d+)/ $1 * 2 /e; } Well, the grep one is cleaner to me - less lines to read. Others may dissagree, and I wouldn't include it when teaching someone for the first time how to do that. -- Brian Hatch "I'm thinking .. pastels!" Systems and Security Engineer http://www.ifokr.org/bri/ Every message PGP signed From spug at ifokr.org Sun Apr 20 23:52:29 2003 From: spug at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) In-Reply-To: <008a01c307bf$bd4e0220$b440fea9@RAnderson> References: <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <001401c306d9$d34c78e0$b440fea9@RAnderson> <20030420015423.GN12203@ifokr.org> <008a01c307bf$bd4e0220$b440fea9@RAnderson> Message-ID: <20030421045229.GB18633@ifokr.org> You can't tell me that this part of your code: > @doubled = map { ($x = $_) =~ s/(\d+)/$1 * 2/e; ^^^^^^^^^ won't confuse and scare new users more than 'grep' would. Assignment in parens on the left of a s// ? Now that's just substituting a not-immediately-obvious grep feature with something that requires detailed knowledge of the order of operations/precedence. TMTOWTDIC (There's more than one way to do it confusingly) -- Brian Hatch "Don't use color Systems and unless you mean it." Security Engineer --Steve Jobs http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20030420/9a639d36/attachment.bin From kahn at cpan.org Mon Apr 21 00:56:36 2003 From: kahn at cpan.org (Jeremy Kahn) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) In-Reply-To: <008a01c307bf$bd4e0220$b440fea9@RAnderson> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <001401c306d9$d34c78e0$b440fea9@RAnderson> <20030420015423.GN12203@ifokr.org> <008a01c307bf$bd4e0220$b440fea9@RAnderson> Message-ID: <3EA38814.7050600@cpan.org> Richard Anderson wrote: >This use of grep exploits a lesser-known side effect of the function and >bypasses it's main purpose, which is to select elements of a list. If you >want to apply a transform to every element of a list, Perl provides the map >function: > >map { $_ =~ s/(\d+)/$1 * 2/e } @list; > > First of all, the $_ =~ is unnecessary. This could be written: map { s/(\d+)/$1*2/e } @list; Second, both of these uses of 'map' are confusing and not-recommended, since they use map in a void context. (Brian's [ab]use of 'grep' also sins.) See PerlFAQ 6, (`perldoc -q "map in a void"`) which reads: > Found in /usr/lib/perl5/5.8.0/pod/perlfaq6.pod > What's wrong with using grep or map in a void context? > > The problem is that both grep and map build a return list, > regardless of the context. This means you're making > Perl go to > the trouble of building a list that you then just throw > away. > If the list is large, you waste both time and space. > If your > intent is to iterate over the list then use a for loop > for this > purpose. So, rewrite again as: foreach (@list) { s/(\d+)/$1*2/e }; >or, preserving the input @list: > >@doubled = map { ($x = $_) =~ s/(\d+)/$1 * 2/e; > $x; > } @list; > Yikes. I have to agree with Brian (and as a teacher) that phrases[1] like ($x = $_) =~ ... are very very hard. Where does a novice even start to look that up? At least it won't blow up my shell when I type "perldoc -f map". By contrast, have you ever tried `perldoc -f $_` in a bash shell? Do it *only* immediately after doing something safe, like "echo foo". Caveat user... If preserving the input list is critical, I recommend the KISS approach: @doubled = @list; # keep original @list unchanged foreach (@doubled) { s/(\d+)/$1 * 2/e; # double the first set of digits. } Just my $0.02. --jeremy [1] I am using the Perl 6 operator '...', pronounced "yadda yadda yadda", in this example. From scott+spug at mail.dsab.rresearch.com Mon Apr 21 11:29:44 2003 From: scott+spug at mail.dsab.rresearch.com (Scott Blachowicz) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Re: Readable, well-written code (was: Best One-Liners and Scripts for UNIX) In-Reply-To: <3EA38814.7050600@cpan.org> References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <001601c306b1$789589f0$0200a8c0@computer> <001401c306d9$d34c78e0$b440fea9@RAnderson> <20030420015423.GN12203@ifokr.org> <008a01c307bf$bd4e0220$b440fea9@RAnderson> <3EA38814.7050600@cpan.org> Message-ID: <200304211629.h3LGTov06287@mail.pm.org> Jeremy Kahn wrote: > Yikes. I have to agree with Brian (and as a teacher) that phrases[1] like > > ($x = $_) =~ ... > > are very very hard. Where does a novice even start to look that up? At > least it won't blow up my shell when I type "perldoc -f map". By > contrast, have you ever tried `perldoc -f $_` in a bash shell? Do it > *only* immediately after doing something safe, like "echo foo". Caveat > user... It may be "hard", but it's a standard idiom for altering a copy of something in perl. Just like natural languages, where does one normally go to find out about idiomatic use like that? One of those things that is learned through experience, I guess? You can do similar things in C++ if your operator=()'s return refs to their objects (as is normally recommended): (a = b) = ...; // [1] Since the 'a = b' returns a reference to 'a', you can assign into it. Of course, I think it looks a bit strange to do that and for some reason I think of it as being more natural in perl. Ah well... Scott [1] I am using the C++0x operator '...', pronounced "yadda yadda yadda", in this example. :)) From christopher.w.cantrall at boeing.com Mon Apr 21 12:26:04 2003 From: christopher.w.cantrall at boeing.com (Cantrall, Christopher W) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX Message-ID: <04088F154165F84E89F96113157E4B61101DFD@XCH-NW-11.nw.nos.boeing.com> > There was one code sample posted early on in this thread that spent > about 7 lines to implement the generic input reading loop that -n > gives you for free; I followed up with a one-line version of that > part, that showed it for what it really was, a Perl implementation > of a simple sed editing command. Is this magic? Not in my book > (if you'll pardon the pun); instead, it's just a worthwhile > simplification that lets the reader focus on the data processing > task, instead of having to wade through boilerplate infrastructure > that has already been factored out by The Larry and memorialized in > "-n". When I wrote that, and later when I posted it, I had a feeling that it could be made into a one-liner, but I didn't know how clean that one-liner would be. That example exemplifies for me one of the things I love about Perl - you can ignore the dirty, boring, and easy to mess up details if you want to: they're taken care of already. You want to loop through your file, substitute based upon a regex, and then print that file back out with the same name, but keep a backup? No problem, use -p, and -i.bak on the command line. You say you want to see where the magic comes from? Read perldoc perlrun, it's all in there. (Almost all, there are some tricks in perlfaq.) You need to use a module to do that clever file manipulation? OK, see the -M switch in perlrun, and you can use Quantum::Superpositions in a one-liner. :) I've seen it done on perlmonks. Heh, Randal Schwartz posted a snippet to perlmonks ( http://perlmonks.org/index.pl?node_id=224272 ) which could probably be a one-liner - it's HTML tidy using XML::LibXML. Type one line into your shell, and *poof* you've cleaned up some HTML files. Is that power? I think that's a great chainsaw. > > What's the other way to say it? Write Once, Read Never? Using command line switches and some shortcuts seems to be an intelligent use of programmer resources. Why write (and debug) loops and file interaction if you can let the language take care of that for you? Read how it performs those actions, then use that functionality. (Read once, write many. :) If you think your maintenance programmer won't know a trick, put in a pointer comment to some instruction (# see perldoc -f map). I've known that Perl was really cool, and as I learn more about it, I'm seeing more coolness. And I'm realizing that I'm the kind of person who finds a programming language cool. :) ________________________________________ Christopher Cantrall Structural Engineer, 767 Fuselage phone: 425-342-4131 fax: 425-717-3174 M/C 0Y-12 -- 40-83 E7 Christopher.W.Cantrall@Boeing.com > -----Original Message----- > From: SPUG-list-owner [mailto:tim@consultix-inc.com] > Sent: Sunday, April 20, 2003 11:06 AM > To: Bob Hiltner > Cc: spug-list@pm.org > Subject: Re: SPUG:Best One-Liners and Scripts for UNIX > > > On Sat, Apr 19, 2003 at 01:22:59PM -0700, Bob Hiltner wrote: > > > Seeing all the one-liners (not this post particularly) brings to > > mind one of the great things about PERL. You don't need code > > obfuscation utilities for IP protection. It's done automatically at > > the source code level! ;^) What's the other way to say it? Write > > Once, Read Never? ... (yadda, yadda, yadda :) > > On a more serious note... that is one of the things that > does make me shy > > away from getting into perl in a serious way... too much > magic. This stuff > > that (perhaps) makes sense to the initiated and the high > priests is like > > reading binaries to the casual perler. > > I always wonder what people are specifically talking about when > they see "magic" in the kind of code we've been slinging around here. > > Is it magic that perl "-n" gives you a free loop? If so, is it also > magic that "grep -i" ignores case, or "sed 's///g'" does multiple > substitutions? Not in my book. There's plenty of "magical" > (surprising and automatic) activity in Perl, but I don't recall > seeing any of it here. > > There was one code sample posted early on in this thread that spent > about 7 lines to implement the generic input reading loop that -n > gives you for free; I followed up with a one-line version of that > part, that showed it for what it really was, a Perl implementation > of a simple sed editing command. Is this magic? Not in my book > (if you'll pardon the pun); instead, it's just a worthwhile > simplification that lets the reader focus on the data processing > task, instead of having to wade through boilerplate infrastructure > that has already been factored out by The Larry and memorialized in > "-n". > > As a case of what most of us might call "magic" in Perl, but > I'd perhaps call "tomfoolery" instead, "eof()" and "eof" do very > different things, as do "use Abc()" and "use Abc". This is the > kind of thing that I personally find very reprehensible in Perl, > because programmers are led by other aspects of the language to > believe that parentheses around argument lists are optional, and > without any intrinsic meaning of their own. That's "bad magic", IMHO. > > And of course there's "autovivification" as another example of > magic, but in Perl's defense I'd say it usually does what you meant > it to anyway, and in any case you can skirt the issue by > initializing on your own the objects it would create. > > > I've been doing more .Net stuff for a while, and I feel the > > understandability of perl quickly slipping away when I (try to) read > > stuff like this. I don't see the same issues at all when I get away > > from, say, C for a while. Is that just the idioms of the language? > > Raw C provides no shortcuts, so one must always code all the routine > data processing minutiae (unless you extend the language with > macros) that we're allowed to invoke through invocation options > like -n in Perl. Sure, that makes it more readable, in the sense > that every tiny detail is spelled out, but IMHO that also makes it > less comprehendible, because it's too easy to miss the view of the > trees for that of the forest. ... (yadda, yadda, yadda) > Happy Easter, everybody! Eat plenty of chocolate. . . > > -Tim > *------------------------------------------------------------* > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > | CEO, JAWCAR ("Just Another White Camel Award Recipient") | > | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > | Watch for my Book: "Minimal Perl for Shell Programmers" | > *------------------------------------------------------------* > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: www.seattleperl.org From ingy at ttul.org Tue Apr 22 16:44:34 2003 From: ingy at ttul.org (Brian Ingerson) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Fw: MOSS meeting May 3rd, 2-5 pm (Open Source social) Message-ID: <20030422144434.F25357@ttul.org> ----- Forwarded message from Kevin Altis ----- From: "Kevin Altis" Date: Tue, 22 Apr 2003 14:21:10 -0700 To: "Brian Ingerson" Cc: "Ward Cunningham" , "Oso Martin" , ptkwt@aracnet.com, chromatic@oreilly.com, pundit@teleport.com, cooper@cooper.stevenson.name, "Allan Abravanel" , joejava@attbi.com, bart@cs.pdx.edu, "Pete Mackie" , "Charlie Kawasaki" , "'Rose Marshall'" , "'Rich Bader'" , "'Larry Wade'" , "Michael Lee Squires" Subject: MOSS meeting May 3rd, 2-5 pm (Open Source social) X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) For up-to-date information and links, please see the MOSS home page: http://moss.freepan.org/ Information from the home page is duplicated below. We look forward to seeing you at the first MOSS meeting! Please distribute this announcement to your user groups, friends and co-workers involved in open source. Everyone is welcome. If you have questions, please email Kevin Altis at the address below. ka --- Kevin Altis altis@semi-retired.com http://altis.pycs.net/ ============================================================ The first MOSS meeting will be held at the Lucky Lab on May 3rd from 2-5 pm. This is your opportunity to meet other Open Source developers and advocates in Oregon. If you want to confirm that you're attending, please add your name to the Attendees page. http://moss.freepan.org/index.cgi?Attendees WHO: Anyone interested in Open Source in Oregon. We expect developers and advocates of well known projects like Apache, Linux, Perl, PHP, Python, Ruby, MySQL, and PostgreSQL, as well as lesser-known projects to attend. There will also be people involved in the Oregon Open Source bill (HB 2892) and the Personal Telco wireless project attending. WHAT: MOSS social. There will be a brief intro at the beginning, but otherwise this will be a social meeting without a fixed agenda. We will provide a white board and wiki to capture who attended and what projects they are involved in. Wireless connectivity will likely not be available at this first event. If we are able to arrange wireless for the event, we will post an update on this page. WHERE: Lucky Labrador Brew Pub (Directions) http://www.luckylab.com/lab_trans.html 915 SE Hawthorne Boulevard Portland, Oregon 97214 (503)236-3555 WHEN: May 3rd, from 2-5 PM (Saturday afternoon) WHY: Meet other people working on Open Source projects in the Portland Metro Area. If you have an interest in promoting Open Source in Oregon or just want to find out what Open Source developers on Linux, Mac OS X, Solaris, Windows, etc. are doing in Oregon then this is the place to be. The Lucky Lab has food, beer, and wine (menu). http://www.luckylab.com/lab_menu.html * * * Neither the Lucky Lab or organizers will be responsible for lost or stolen goods. We don't recommend that you bring any equipment unless you are willing to keep track of it yourself. * * * ----- End forwarded message ----- From beckyls at u.washington.edu Wed Apr 23 13:31:10 2003 From: beckyls at u.washington.edu (Rebecca L. Schmidt) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:UW UNIX/Linux Program Message-ID: Hi all, Do you want to use your Perl skills and learn to plan, support and administer UNIX/Linux networks? If so, the University of Washington UNIX/Linux Certificate Program may be for you. This eight-week, hands-on program is designed for people with basic UNIX/Linux knowledge. It is especially useful for individuals preparing for career change or advancement. This program serves as preparation for Linux Professional Institute (LPI) Certification. Attend a free information meeting next week to meet the expert instructor and learn more: Thursday, May 1, 2003, 6-7 p.m., UW Educational Outreach, 2445 140th Ave. NE, Suite B-100, Bellevue Applications are being accepted now for the program that begins in June. Please see the program website for more information: http://www.extension.washington.edu/extinfo/certprog/uad/uad_main.asp Please feel free to contact me if you have specific questions. I'd be happy to hear from you! Best regards, Rebecca Schmidt Program Manager University of Washington Extension beckyls@u.washington.edu; rschmidt@ese.washington.edu (206) 221-6243 From jimfl at tensegrity.net Wed Apr 23 19:12:57 2003 From: jimfl at tensegrity.net (Jim Flanagan) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <20030416174930.A25359@timji.consultix-inc.com> Message-ID: On Wed, 16 Apr 2003, Tim Maher wrote: > So please give some thought as to what Perl one-liners or > small scripts you value for your UNIX/Linux work, and post > them to the list so we can discuss them. Dunno if I'm late to this party, but a very handy script for dealing with mail messages is: perl -MMail::Internet -e 'Mail::Internet->new([<>])->print_body' Which, if you cat a mail message through it, pipes out only the body. -- ::jimfl http://jimfl.tensegrity.net mailto:jimfl%40t%65ns%65gr%69ty.n%65t From MichaelRunningWolf at att.net Thu Apr 24 12:00:32 2003 From: MichaelRunningWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Linux Northwest *this* weekend Message-ID: http://www.linuxnorthwest.com/ -- Michael R. Wolf All mammals learn by playing! MichaelRunningWolf@att.net From MichaelRunningWolf at att.net Fri Apr 25 13:12:40 2003 From: MichaelRunningWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Linux Northwest *this* weekend In-Reply-To: <20030425171933.GA68474@wokkil.pair.com> References: <20030425171933.GA68474@wokkil.pair.com> Message-ID: Asim Jalis writes: > On Thu, Apr 24, 2003 at 10:00:32AM -0700, Michael R. Wolf wrote: > > http://www.linuxnorthwest.com/ > > I just saw this on use.perl.org. I am surprised no one announced it > here, earlier. Me, too. Luckily, a friend reminded me. My "town crier" position has taken a back seat to business development. > It looks like PogoLinux's chartered buses to the event are already > full. I suggest that folks use this board to offer carpool rides, then connect outside of this group. Alternatively, you could show up at the bus site, and either get an empty seat or collect extra carpoolers for a caravan or car-a-bus-a-van :-) -- Michael R. Wolf All mammals learn by playing! MichaelRunningWolf@att.net From tim at consultix-inc.com Fri Apr 25 14:45:51 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Linux Northwest *this* weekend In-Reply-To: References: <20030425171933.GA68474@wokkil.pair.com> Message-ID: <20030425124551.A9445@timji.consultix-inc.com> On Fri, Apr 25, 2003 at 11:12:40AM -0700, Michael R. Wolf wrote: > Asim Jalis writes: > > > On Thu, Apr 24, 2003 at 10:00:32AM -0700, Michael R. Wolf wrote: > > > http://www.linuxnorthwest.com/ > > > > I just saw this on use.perl.org. I am surprised no one announced it > > here, earlier. I did, but maybe you didn't notice. And now I'm too busy preparing my presentations to think about reminding anybody. Sorry! > Me, too. Luckily, a friend reminded me. My "town crier" position has > taken a back seat to business development. > > > It looks like PogoLinux's chartered buses to the event are already > > full. > > I suggest that folks use this board to offer carpool rides, then > connect outside of this group. I'll be heading out very early to set up my booth, otherwise I'd be happy to offer somebody a lift. But you're better off sleeping in a bit more! Hope to see you there! -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From sthoenna at efn.org Fri Apr 25 16:36:06 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: <002401c30486$85739860$321d10ac@RAnderson> References: <20030416174930.A25359@timji.consultix-inc.com> <002401c30486$85739860$321d10ac@RAnderson> Message-ID: On Wed, 16 Apr 2003 19:10:16 -0700, richard@richard-anderson.org wrote: >#! /usr/bin/perl >while (<>) { > eval; > if ($@) { print $@ } >} I used to do that all the time manually, as: perl -wlne'eval;print$@if$@' Then I made a script that did: perl -MDevel::Peek -MData::Dumper -MScalar::Util=/./ -wlne'eval;print$@if$@' to provide some useful debugging tools by default. The // tells an Exporter-based module to import all symbols matching a pattern. Unfortunately, I upgraded Scalar::Util and started getting an error because the new isvstring only works with 5.8.1 and above. Now I have: perl -MDevel::Peek -MData::Dumper '-MScalar::Util=/^(?!isvstring)/' -wlne'eval;print$@if$@' From jay at scherrer.com Mon Apr 28 12:40:14 2003 From: jay at scherrer.com (Jay Scherrer) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Tims talk at Linux-Fest 2003 :-) Message-ID: <200304281040.14664.jay@scherrer.com> Tim, You did it again. I wanted to thank you for your presentation at the Linux-Fest. The attendees got a full dose of that Spugery feeling that day. Good Job! Jay From john.brittingham at attws.com Mon Apr 28 15:43:52 2003 From: john.brittingham at attws.com (Brittingham, John) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Problems getting rows from sybase db Message-ID: <47AB1611568F5344B30736563AAA895C015F7930@WA-MSG07-BTH.wireless.attws.com> Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/bmp Size: 470 bytes Desc: ole0.bmp Url : http://mail.pm.org/pipermail/spug-list/attachments/20030428/589d40f8/attachment.bin From john.brittingham at attws.com Mon Apr 28 15:45:58 2003 From: john.brittingham at attws.com (Brittingham, John) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:RE: Problems getting rows from sybase db Message-ID: <47AB1611568F5344B30736563AAA895C015F7931@WA-MSG07-BTH.wireless.attws.com> Oops I meant to type: while(my @data = $dbh->dbnextrow(0)) This should be: while(my @data = $dbh->dbnextrow) > -----Original Message----- > From: Brittingham, John > Sent: Monday, April 28, 2003 1:44 PM > To: spug-list@pm.org > Subject: Problems getting rows from sybase db > > Having problem get dbnextrow to reurn the row, eventhough dbresults returns 1 > > #!/usr/local/bin/sybperl5 > ################################################## > # test_axys.pl # > # John Brittingham # > # # > # Return: @data (regional and main db servers) # > # # > ################################################## > require "axys_config.pl"; > require "pagelib.pl"; > if (!defined($NWRSDB_LIB)) > { require "nwrsdb_lib.pl"; } > if (!defined($NWRSCOMMON_LIB)) > { require "nwrscommon_lib.pl"; } > if (!defined($AXYSLIB)) > { require "axys_lib.pl"; } > > $dbh = Sybase::DBlib->dblogin($NavDBUsername, $NavDBPassword, $NavDBServer, $AppName); > print("Data base Info ".$NavDBUsername." ".$NavDBPassword." ".$NavDBServer." ".$AppName."\n"); > $dbh->dbcmd("select NSS.name, NPDB.name from PFWUtil..NavAreaPhysicalDbSqlServer NAPDBSS, ". > "PFWUtil..NavAreaLogicalDb NALDB, PFWUtil..NavLogicalDb NLDB, PFWUtil..NavPhysicalDb NPDB, ". > "PFWUtil..NavSqlServer NSS, PFWUtil..NavArea NA where NPDB.oid = NAPDBSS.oidPhysicalDb ". > "and NSS.oid = NAPDBSS.oidSqlServer and NLDB.oid = NALDB.oidLogicalDb ". > "and NALDB.oidAreaPhysicalDbSqlServer = NAPDBSS.oid and NALDB.oidArea = NA.oid ". > "and NLDB.name = 'AXYSDB' and lower(NA.name) like lower('Western%')\n"); > $dbh->dbsqlexec; > while ($results = $dbh->dbresults != 2) > { > print("results=".$results."\n"); > > while(my @data = $dbh->dbnextrow(0)) > { > print(@data."\n"); > } > > } > > > > John Brittingham > Developer 1 > AT&T Wireless Services > Bothell 7 > Cell: 206-484-2042 > --------------------------------------------------------------- > "Non est mea culpa!!!!" > << OLE Object: Picture (Metafile) >> > From jgardn at alumni.washington.edu Mon Apr 28 16:19:19 2003 From: jgardn at alumni.washington.edu (Jonathan Gardner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Problems getting rows from sybase db In-Reply-To: <47AB1611568F5344B30736563AAA895C015F7930@WA-MSG07-BTH.wireless.attws.com> References: <47AB1611568F5344B30736563AAA895C015F7930@WA-MSG07-BTH.wireless.attws.com> Message-ID: <200304281419.19510.jgardn@alumni.washington.edu> On Monday 28 April 2003 13:43, Brittingham, John wrote: > Having problem get dbnextrow to reurn the row, eventhough dbresults returns > 1 > Couple of friendly comments that have nothing to do with your question (and thus may utterly be disregarded with prejudice): 1) Have you looked into using DBI? I know from experience that going from Sybase to Oracle to PostgreSQL was a lot easier because DBI didn't change between them. I can't speak for your situation, so you may have a very good reason for using what you are using. 1.5) You don't need to type so much because the variables work like shell in quotes. print("Data base Info ".$NavDBUsername." ".$NavDBPassword." ".$NavDBServer." ".$AppName."\n"); is shorter and possibly morel legible when written as: print("Data base Info $NavDBUsername $NavDBPassword $NavDBServer $AppName\n"); 2) For large bits of text. consider using here docs instead of quotes to increase legibility. A here doc would work like this: $dbh->dbcmd(<dbcmd(< Message-ID: Another buttinsky... > 3) And since I don't save much by saving lines because I use a > here doc, I > would rewrite that statement like this: > > $dbh->dbcmd(< select NSS.name > , NPDB.name > from PFWUtil..NavAreaPhysicalDbSqlServer NAPDBSS > , PFWUtil..NavAreaLogicalDb NALDB > , PFWUtil..NavLogicalDb NLDB > , PFWUtil..NavPhysicalDb NPDB > , PFWUtil..NavSqlServer NSS > , PFWUtil..NavArea NA > where NPDB.oid = NAPDBSS.oidPhysicalDb > and NSS.oid = NAPDBSS.oidSqlServer > and NLDB.oid = NALDB.oidLogicalDb > and NALDB.oidAreaPhysicalDbSqlServer = NAPDBSS.oid > and NALDB.oidArea = NA.oid > and NLDB.name = 'AXYSDB' > and lower(NA.name) like lower('Western%') > SQL > > This makes it easier to add and remove columns/tables/conditions. Moreover, you can use the same here doc name (e.g. SQL) each time. So by structuring all of your DB calls in this manner and using the same name each time you can go back with a _simple_ script and pull out all of the SQL statements for your documentation. Or for your DBA to analyze for the purpose of tweaking indices in your database. On my last project I wrote a script that would pre-process Perl into something that Doxygen (a public-domain documentation tool) would consume and a side-effect was a page with all the SQL statements on it. Useful result for little work. 4) It can be very worthwhile to preprocess statement handles for oft-used statements. See the DBI doc. See the DBI doc or O'Reilly's 'Programming the Perl DBI.' Make no mistake, moving from one database to another is not completely painless. I wrote one project using SQL Server and deployed using Oracle. Mostly it's OK, but (ominous background music...) _all SQLs are NOT alike_. Date formatting was one of the gotchas as I recall. But at least if you're using DBI the transition is way _less_ painful than if you're not. Marc M. Adkins P.S. Like, there's a Perl binding to Axys now? Awesome... -- mma From sthoenna at efn.org Sun Apr 27 00:49:17 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> Message-ID: On Sat, 19 Apr 2003 10:37:13 -0700, tim@consultix-inc.com wrote: > ($fields = shift) =~ /^[\d,.]+$/g or That trips a warning if the script is given no args. Make it: $fields = shift and $fields =~ ... > @fields = eval " ( $fields ) "; # 5,2..4 => 5,2,3,4 The parens there aren't necessary. You need parens for something like: @fields = (5,2..4) just for correct precedence ('=' is lower precedence than ','), but with the eval there, there is no precedence problem. Parens almost never affect anything besides precedence. (Two major exceptions are around the left operands of '=' and 'x': there the behaviour of the operator completely changes. I thought there was a third important exception but can't remember what it was.) From MichaelRunningWolf at att.net Tue Apr 29 08:48:06 2003 From: MichaelRunningWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Open Source Avocacy kick-off meeting in Portland, OR Message-ID: SPUG-ers, It's road trip time again.... Here's an announcement from the PDX PM mailing list. There's a new Open Source Advocacy group starting in Portland. Anyone want to make a road trip out of it? I may use this as an excuse to visit friends, but we could carpool in one direction, and bus/train the other direction. That's what I did last weekend for Linux Fest Northwest. Michael Wolf P.S. And in the "it's a small world" category, while returning from LFNW I bumped into Michael Schwern at 1 a.m. during the 15 minutes I spent in the Seattle Greyhound station. He was getting on the Greyhound bus that I had just gotten off. P.P.S. Heck, for that matter, I bumped into Ingy at the 20,000+ peace rally earlier this year. Must be taht geek-dar. P.P.P.S. I could *definately* pick the geeks out from the cruisers at Perl Whirl '02. Kinda reminded me of some scene from MIB where the special agents had a deeper view of "travelers". The Geek Cruise folks were obviously different to me than the remainder of the Holland America clientele. P.P.P.P.S. -- Perl Whirl '03 is coming. I had a great time on the '02 version. Check it out. I'd recommend it for folks with money or budget. Great value. Great fun. Great learning/networking opportunitiy. http://geekcruises.com/ Brian Ingerson writes: [...] > For up-to-date information and links, please see the MOSS home page: > > http://moss.freepan.org/ > > Information from the home page is duplicated below. We look forward to > seeing you at the first MOSS meeting! Please distribute this announcement to > your user groups, friends and co-workers involved in open source. Everyone > is welcome. If you have questions, please email Kevin Altis at the address > below. > > ka > --- > Kevin Altis > altis@semi-retired.com > http://altis.pycs.net/ > > ============================================================ > > The first MOSS meeting will be held at the Lucky Lab on May 3rd from 2-5 pm. > This is your opportunity to meet other Open Source developers and advocates > in Oregon. If you want to confirm that you're attending, please add your > name to the Attendees page. > > http://moss.freepan.org/index.cgi?Attendees > > WHO: > Anyone interested in Open Source in Oregon. We expect developers and > advocates of well known projects like Apache, Linux, Perl, PHP, Python, > Ruby, MySQL, and PostgreSQL, as well as lesser-known projects to attend. > There will also be people involved in the Oregon Open Source bill (HB 2892) > and the Personal Telco wireless project attending. > > WHAT: > MOSS social. There will be a brief intro at the beginning, but otherwise > this will be a social meeting without a fixed agenda. We will provide a > white board and wiki to capture who attended and what projects they are > involved in. Wireless connectivity will likely not be available at this > first event. If we are able to arrange wireless for the event, we will post > an update on this page. > > WHERE: > Lucky Labrador Brew Pub (Directions) > > http://www.luckylab.com/lab_trans.html > > 915 SE Hawthorne Boulevard > Portland, Oregon 97214 > (503)236-3555 > > WHEN: > May 3rd, from 2-5 PM (Saturday afternoon) > > WHY: > Meet other people working on Open Source projects in the Portland Metro > Area. If you have an interest in promoting Open Source in Oregon or just > want to find out what Open Source developers on Linux, Mac OS X, Solaris, > Windows, etc. are doing in Oregon then this is the place to be. > > The Lucky Lab has food, beer, and wine (menu). > > http://www.luckylab.com/lab_menu.html > > * * * > Neither the Lucky Lab or organizers will be responsible for lost or stolen > goods. We don't recommend that you bring any equipment unless you are > willing to keep track of it yourself. > * * * > > > ---------- > > _______________________________________________ > Pdx-pm-list mailing list > Pdx-pm-list@mail.pm.org > http://mail.pm.org/mailman/listinfo/pdx-pm-list > -- Michael R. Wolf All mammals learn by playing! MichaelRunningWolf@att.net From tim at consultix-inc.com Tue Apr 29 12:25:26 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX In-Reply-To: References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> Message-ID: <20030429102526.A13160@timji.consultix-inc.com> On Sat, Apr 26, 2003 at 10:49:17PM -0700, Yitzchak Scott-Thoennes wrote: > On Sat, 19 Apr 2003 10:37:13 -0700, tim@consultix-inc.com wrote: > > ($fields = shift) =~ /^[\d,.]+$/g or > > That trips a warning if the script is given no args. Make it: > $fields = shift and $fields =~ ... Good idea, but that's not the same, because they could ask for field #0 only, and that would be treated the same as a missing argument due to its false value. I can't see the original program I submitted at the moment, but I would usually have had a "@ARGV > 0 or die" or equivalent in the BEGIN block to handle this kind of argument checking. > > @fields = eval " ( $fields ) "; # 5,2..4 => 5,2,3,4 > > The parens there aren't necessary. You need parens for something I wasn't writing for the benefit of the compiler, but for that of the reader, who I think will find it easier to understand that a list is being formed with the parens there (and they don't bother the compiler). > like: @fields = (5,2..4) just for correct precedence ('=' is lower > precedence than ','), but with the eval there, there is no precedence > problem. Parens almost never affect anything besides precedence. > (Two major exceptions are around the left operands of '=' and 'x': > there the behaviour of the operator completely changes. I thought But my parens *are* on the right side of an "=", so if one glosses over the eval, it reads like @fields = ( 5,2..4 ). That was my intention, anyway; obviously, you know too much about Perl to appreciate this illusion! 8-} > there was a third important exception but can't remember what it was.) You're probably thinking of eof() vs eof, and use Module() vs use Module, in which the parens fundamentally change the obtained behavior. -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From sthoenna at efn.org Tue Apr 29 19:41:57 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Best One-Liners and Scripts for UNIX References: <20030416174930.A25359@timji.consultix-inc.com> <20030417034433.GL12203@ifokr.org> <20030417140716.GW12203@ifokr.org> <20030417224240.A30335@timji.consultix-inc.com> <20030418133302.GX12203@ifokr.org> <20030419103713.A3251@timji.consultix-inc.com> <20030429102526.A13160@timji.consultix-inc.com> Message-ID: On Tue, 29 Apr 2003 10:25:26 -0700, tim@consultix-inc.com wrote: >On Sat, Apr 26, 2003 at 10:49:17PM -0700, Yitzchak Scott-Thoennes wrote: >> On Sat, 19 Apr 2003 10:37:13 -0700, tim@consultix-inc.com wrote: >> > ($fields = shift) =~ /^[\d,.]+$/g or >> >> That trips a warning if the script is given no args. Make it: >> $fields = shift and $fields =~ ... > >Good idea, but that's not the same, because they could ask for field >#0 only, and that would be treated the same as a missing argument due >to its false value. I can't see the original program I submitted at >the moment, but I would usually have had a "@ARGV > 0 or die" or >equivalent in the BEGIN block to handle this kind of argument checking. Sorry, I snipped too much of your code. The line I quote is the "@ARGV > 0 or die" equivalent. And you adjust @F so that field 1 is the first field. However, if field 0 were allowed, you could say: defined($fields = shift) and $fields =~ /^[\d,.]+$/g or die "Usage: $0 '2,1,3,4..7' [ file ... ]"; or use the completely imaginary C operator :) $fields = shift dand $fields =~ ... >> The parens there aren't necessary. You need parens for something > >I wasn't writing for the benefit of the compiler, but for that of the >reader, who I think will find it easier to understand that a list is >being formed with the parens there (and they don't bother the compiler). It's the illusion that () creates a list that I find objectionable. >> like: @fields = (5,2..4) just for correct precedence ('=' is lower >> precedence than ','), but with the eval there, there is no precedence >> problem. Parens almost never affect anything besides precedence. >> (Two major exceptions are around the left operands of '=' and 'x': >> there the behaviour of the operator completely changes. I thought > >But my parens *are* on the right side of an "=", so if one glosses >over the eval, it reads like @fields = ( 5,2..4 ). That was my >intention, anyway; obviously, you know too much about Perl to appreciate >this illusion! 8-} Here are some fun things to try: sub context { print wantarray ? "list" : defined wantarray ? "scalar" : "void" } $x = context; # scalar context $x = (context); # still scalar context, () on right have no effect ($x) = context; # list context, () on left force list context on right ($x) = (context); # still list context, () on right have no effect @x = context; # list context $x ? ($x) : ($x) = context; # if ?: on left, check its 2nd & 3rd operands for () From andrew at sweger.net Wed Apr 30 11:37:46 2003 From: andrew at sweger.net (Andrew Sweger) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:No breakfast or lunch at OSCON Message-ID: Something that kind of surprised me about this year's OSCON schedule is the absense of breakfast and lunch provided as part of the convention. For those at last year's in San Diego, you were treated to some great food (probably the best in the history of the Perl Conference). Looks like O'Reilly's cut back this year. The good news is folks should be in easy reach of several decent restaurants in the area. Of course, most folks will be more concerned with the *content* of the conference and tutorials. -- Andrew B. Sweger -- The great thing about multitasking is that several things can go wrong at once. From tim at consultix-inc.com Wed Apr 30 14:51:41 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Good PDX Hotel for OSCON? In-Reply-To: References: Message-ID: <20030430125141.A22234@timji.consultix-inc.com> Can anybody recommend a nice hotel near the OSCON conference hotel? I've stayed there (the downtown Portland Marriott) many times in recent years for $45-75/night, and don't want to pay the "captive audience" rate (of nearly $200 before tax, if memory serves) just because I'm attending a conference. I figure I should be able to get a very nice one nearby for about $50/night. Any recommendations? -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From daryn at marinated.org Wed Apr 30 15:58:51 2003 From: daryn at marinated.org (Daryn Nakhuda) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Good PDX Hotel for OSCON? References: <20030430125141.A22234@timji.consultix-inc.com> Message-ID: <001301c30f5b$4e0e33a0$6501a8c0@platypus> Don't know what the rates are for your dates , but usually in the 90-120 range, very nice, and very close to the marriott, are the hotel lucia, hotel vintage plaza, and paramount hotel. I've stayed at them all, and would recommend any of them. ----- Original Message ----- From: "SPUG-list-owner" To: Cc: "Tim Maher" Sent: Wednesday, April 30, 2003 12:51 PM Subject: SPUG:Good PDX Hotel for OSCON? > > Can anybody recommend a nice hotel near the OSCON conference hotel? > I've stayed there (the downtown Portland Marriott) many times in > recent years for $45-75/night, and don't want to pay the "captive > audience" rate (of nearly $200 before tax, if memory serves) just > because I'm attending a conference. I figure I should be able > to get a very nice one nearby for about $50/night. > > Any recommendations? > > -Tim > *------------------------------------------------------------* > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > | CEO, JAWCAR ("Just Another White Camel Award Recipient") | > | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > | Watch for my Book: "Minimal Perl for Shell Programmers" | > *------------------------------------------------------------* > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: www.seattleperl.org > > From wyllie at dilex.net Wed Apr 30 16:34:15 2003 From: wyllie at dilex.net (Andrew Wyllie) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Open Source Recruiters? Message-ID: <20030430213415.GF11329@sharkey.dilex.net> Hi all, I'm wondering if anybody could recommend any recruiters/headhunters that focus on positions that are for Open Source architects/programmers/sys admins (esp. perl, mysql, postgres, mod_perl). Thanks in advance! Andrew From mathin at mathin.com Wed Apr 30 17:24:01 2003 From: mathin at mathin.com (Dan Ebert) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Object property question Message-ID: <1051741440.2943.71.camel@algernon.lan.enic.cc> The Setup: I'm working on a module to manage a membership database. I have it set up so that there is a Member object with properties you can access like my $firstname = $member->firstname(); and change with $member->firstname('new first name'); etc. when a new member is created: $member->initialize(firstname => 'John', lastname => 'Doe'); $member->create(); I insert the data into a table and get the member ID from an auto-incrementing field. The Question: I want to set a new property of the Member object (the ID). So that you can retrieve the ID with $id = $member->id(); In my module I tried: $member->{id} = $id but that didn't work. The only thing I've gotten to work is to return the object ... so that you call the create method like this: $member = $member->create(); which seems a little awkward. Is there a better way? -- Dan Ebert ------------------------------------------------------------- Frisbeetarianism (n.), The belief that, when you die, your soul goes up on the roof and gets stuck there. From jay at scherrer.com Wed Apr 30 18:33:48 2003 From: jay at scherrer.com (Jay Scherrer) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Object property question In-Reply-To: <1051741440.2943.71.camel@algernon.lan.enic.cc> References: <1051741440.2943.71.camel@algernon.lan.enic.cc> Message-ID: <200304301633.48466.jay@scherrer.com> I would do something like: package Member; sub new { my $this = {}; bless $this; return $this; } sub init_newMember { my $this = shift; $this{id} = shift; $this{FirstName} = shift; $this{LastName} = shift; } 1; Then in your script: $member = Member::new(); $id = 0; $firstName = "John"; $lastName = "Doe"; $member->Member::init_newMember($id, $firstName, $lastName); Course I'm just getting the hang of this too. I've found that the line: $member->Member::init_newMember($id, $firstName, $lastName); passes ($member $id $firstName $lastName) to the function in that order. Jay On Wednesday 30 April 2003 03:24 pm, Dan Ebert wrote: > The Setup: > > I'm working on a module to manage a membership database. I have it set > up so that there is a Member object with properties you can access like > > my $firstname = $member->firstname(); > > and change with > > $member->firstname('new first name'); > > etc. > > when a new member is created: > > $member->initialize(firstname => 'John', > lastname => 'Doe'); > $member->create(); > > I insert the data into a table and get the member ID from an > auto-incrementing field. > > The Question: > > I want to set a new property of the Member object (the ID). So that you > can retrieve the ID with > > $id = $member->id(); > > In my module I tried: > > $member->{id} = $id > > but that didn't work. > > The only thing I've gotten to work is to return the object ... so that > you call the create method like this: > > $member = $member->create(); > > which seems a little awkward. > > Is there a better way? From allyn at well.com Wed Apr 30 20:14:34 2003 From: allyn at well.com (Mark Allyn) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Good PDX Hotel for OSCON? In-Reply-To: <20030430125141.A22234@timji.consultix-inc.com> Message-ID: If you are really on the cheap, and you don't mind sharing with others, Portland has two AYH Hostels. Both of them are located well within good bus access to downtown where the con is located. One of the hostels is on Glissen and about 20th Northwest, and the other one, which is my favorite, is located in about 28th and Southeast Hawthorne. Any search engine will pop up more details if you use portland oregon hostels for the search criteria. Good luck! Mark Allyn From tim at consultix-inc.com Wed Apr 30 20:42:21 2003 From: tim at consultix-inc.com (SPUG-list-owner) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Good PDX Hotel for OSCON? In-Reply-To: References: <20030430125141.A22234@timji.consultix-inc.com> Message-ID: <20030430184221.A23122@timji.consultix-inc.com> On Wed, Apr 30, 2003 at 06:14:34PM -0700, Mark Allyn wrote: > > If you are really on the cheap, and you don't mind sharing > with others, Portland has two AYH Hostels. Both of them > are located well within good bus access to downtown where the > con is located. I'm not cheap -- I just like to stay at 4-5 star hotels for around $50, which has been easy to accomplish all around the country since 9/11. The trick is to suss out which one Priceline is offering you before paying for it, which can be accomplished with a little triangulation regarding published amenities and checking with sites like biddingfortravel.com. They're currently showing the 4-star "Hotel Lucia" and Hotel Vintage Plaza at $55, for recent stays. -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | CEO, JAWCAR ("Just Another White Camel Award Recipient") | | tim@Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From smorton at pobox.com Wed Apr 30 20:53:02 2003 From: smorton at pobox.com (Sanford Morton) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Object property question In-Reply-To: <1051741440.2943.71.camel@algernon.lan.enic.cc> Message-ID: Here's one example, if I understand you correctly. Of course if this is a database, you'll also need module routines to read to and write from the database at the appropriate times, including the id number of the last member created. I haven't tested any of this. ### code inside Member.pm ### code inside script package Member; use Member; use strict; my $m = Member->new('Jane', 'Doe'); print $m->id(); my $_lastid = 0; # class vble ==> prints id number print $m->firstname('Mary'); sub new { # constructor ==> changes and prints first name my $class = shift; my $self = {}; $self->_init(@_); return bless $self, $class; } sub _init { # initialization, private my $self = shift; $self->{'_firstname'} = $_[0]; $self->{'_lastname'} = $_[1]; $self->{'_id'} = ++$lastid; } sub firstname { # accessor, public my $self = shift; $self->{'_firstname'} = $_[0] if @_; return $self->{'_firstname'}; } sub id { # accessor, public my $self = shift; return $self->{'_id'}; } I find it useful in module code to prefix with an underscore all internal variables and functions (that aren't documented in the public interface and aren't intended to be used by the user). If you're starved for another introductory Perl object tutorial, you can scan the one at http://www.speakeasy.org/~cgires/modules/ Or, for books, Damian Conway's is my favorite. From kahn at cpan.org Wed Apr 30 21:31:25 2003 From: kahn at cpan.org (Jeremy Kahn) Date: Mon Aug 2 21:36:56 2004 Subject: SPUG:Object property question In-Reply-To: <200304301633.48466.jay@scherrer.com> References: <1051741440.2943.71.camel@algernon.lan.enic.cc> <200304301633.48466.jay@scherrer.com> Message-ID: <3EB086FD.5010006@cpan.org> Jay, Dan -- don't forget that you want to build for the future. You may want to subclass Member someday (temporary members, super-members, moderators, whatever). Jay Scherrer wrote: >I would do something like: >package Member; >sub new >{ >my $this = {}; > bless $this; > return $this; >} > I would rather do it like this: package Member; # take the type as an argument, so that this method can be inherited. # this can be more compact, but it works and is clearer sub new { my $class = shift; # $class will be 'Member' (but *not* when you subclass it) my $instance = bless ({}, $class); $instance->init(@_); # any remaining arguments should be passed to init return $instance; } >sub init_newMember >{ >my $this = shift; >$this{id} = shift; >$this{FirstName} = shift; >$this{LastName} = shift; >} > > rather: # we know it's a Member now, but this method might be used for a subclass # too, so let's just call the method 'init' sub init { my $self = shift; my ($id, $fn, $ln) = @_; $self->{'Member_id'} = $id; $self->{'Member_firstname'} = $fn; $self->{'Member_lastname'} = $ln; } >1; > > Yup. >Then in your script: >$member = Member::new(); > >$id = 0; >$firstName = "John"; >$lastName = "Doe"; >$member->Member::init_newMember($id, $firstName, $lastName); > > No! This method of calling new() can't be inherited -- you're naming the package explicitly, but you'd like to leave yourself the option to re-implement Member so that it borrows a 'new' method from some *other* parent, someday (this is called "refactoring" and is very hip :-/). Furthermore, with the new() as I suggested (calling the init() method from within itself) you can pass the arguments right in: my ($id, $fn, $ln) = (0, 'John', 'Doe'); $member = Member->new($id, $fn, $ln); # isn't that pretty? $member is all done and ready to be used; no need for a second call. The key to the object->method() syntax is to remember that when a method is called like this, it passes the object as an implicit first argument (it's unshifted onto @_). This applies even when it's a literal (like a classname) which is why we get away with Member->new(@args): the method Member::new is called with the argument list ('Member', @args). Note also that if Member::new isn't found, then it checks to see if @Member::ISA has any entries; if it does, it searches those ancestor classes recursively. This is all *very* powerful, and kinda hacked together. I strongly recommend The Damian's book "Object Oriented Perl" -- the first five or six chapters are a great introduction to this subject. >On Wednesday 30 April 2003 03:24 pm, Dan Ebert wrote: > > >>The Setup: >> >>I'm working on a module to manage a membership database. I have it set >>up so that there is a Member object with properties you can access like >> >>my $firstname = $member->firstname(); >> >>and change with >> >>$member->firstname('new first name'); >> >>etc. >> >>when a new member is created: >> >>$member->initialize(firstname => 'John', >> lastname => 'Doe'); >>$member->create(); >> >>I insert the data into a table and get the member ID from an >>auto-incrementing field. >> >>The Question: >> >>I want to set a new property of the Member object (the ID). So that you >>can retrieve the ID with >> >>$id = $member->id(); >> >>In my module I tried: >> >>$member->{id} = $id >> >>but that didn't work. >> >>The only thing I've gotten to work is to return the object ... so that >>you call the create method like this: >> >>$member = $member->create(); >> >>which seems a little awkward. >> >>Is there a better way? >> >> > >_____________________________________________________________ >Seattle Perl Users Group Mailing List >POST TO: spug-list@mail.pm.org >ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list >MEETINGS: 3rd Tuesdays, U-District, Seattle WA >WEB PAGE: www.seattleperl.org > > >