From sheff at pobox.com Tue Sep 25 21:42:26 2001 From: sheff at pobox.com (Keith W. Sheffield) Date: Thu Aug 5 00:07:18 2004 Subject: [Memphis.pm] perl one liner In-Reply-To: Carl Brock Sides's message of "Tue, 21 Nov 2000 15:20:37 -0600" Message-ID: At the last golum meeting I mentioned seeing a perl one liner that just counts the lines in a file. Here it is: perl -lpe '}$_=$.;{' [optional list of files] ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From HPhillips at harrahs.com Wed Sep 26 08:25:17 2001 From: HPhillips at harrahs.com (Hal Phillips) Date: Thu Aug 5 00:07:18 2004 Subject: [Memphis.pm] perl one liner Message-ID: Interesting, I ran this on and AIX s80 w 8gig of ram versus wc -l on a nigh million line file, and the perl won on time.... I wouldn't have guessed it! box:/tmp> timex perl -lpe '}$_=$.;{' hal.tmp 989702 real 6.83 user 5.42 sys 1.41 box:/tmp> timex wc -l hal.tmp 989702 hal.tmp real 11.45 user 9.77 sys 1.68 -Hal Phillips Programmer, Harrahs Entertainment > -----Original Message----- > From: Keith W. Sheffield [SMTP:sheff@pobox.com] > Sent: Tuesday, September 25, 2001 9:42 PM > To: memphis-pm-list@pm.org > Subject: [Memphis.pm] perl one liner > > > At the last golum meeting I mentioned seeing a perl one liner that just > counts the lines in a file. Here it is: > > perl -lpe '}$_=$.;{' [optional list of files] > > > > -------------------------------------------------------------------------- > -- > To unsubscribe, please send email to majordomo@pm.org > with 'unsubscribe memphis-pm-list' in the body of the message. > -------------------------------------------------------------------------- > -- > ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From sml at zfx.com Wed Sep 26 12:43:41 2001 From: sml at zfx.com (Steve Lane) Date: Thu Aug 5 00:07:18 2004 Subject: [Memphis.pm] perl one liner References: Message-ID: <3BB213CD.EE152B2@zfx.com> Hal Phillips wrote: > > Interesting, I ran this on and AIX s80 w 8gig of ram versus wc -l on a nigh > million line file, and the perl won on time.... I wouldn't have guessed it! > > box:/tmp> timex perl -lpe '}$_=$.;{' hal.tmp > 989702 > > real 6.83 > user 5.42 > sys 1.41 > > box:/tmp> timex wc -l hal.tmp > 989702 hal.tmp > > real 11.45 > user 9.77 > sys 1.68 this is likely to be a hair faster: timex perl -ne '}print$.-1 ."\n";{' hal.tmp it's about 1% faster on my machine. if you've got Deparse and want to see what's going on with these examples, run these commands... perl -MO=Deparse -lpe '}$_=$.;{' hal.tmp perl -MO=Deparse -ne '}print$.-1 ."\n";{' hal.tmp -- Steve Lane ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From HPhillips at harrahs.com Wed Sep 26 13:29:11 2001 From: HPhillips at harrahs.com (Hal Phillips) Date: Thu Aug 5 00:07:18 2004 Subject: [Memphis.pm] perl one liner Message-ID: Kewl, thanks! The first time I ran it, it was 22 seconds... but the second and third it was 6.19 and 6.21. I wonder about the 22.... That Deparse is pretty sweet. -hal > -----Original Message----- > From: Steve Lane [SMTP:sml@zfx.com] > Sent: Wednesday, September 26, 2001 12:44 PM > To: memphis-pm-list@pm.org > Subject: Re: [Memphis.pm] perl one liner > > Hal Phillips wrote: > > > > Interesting, I ran this on and AIX s80 w 8gig of ram versus wc -l on a > nigh > > million line file, and the perl won on time.... I wouldn't have guessed > it! > > > > box:/tmp> timex perl -lpe '}$_=$.;{' hal.tmp > > 989702 > > > > real 6.83 > > user 5.42 > > sys 1.41 > > > > box:/tmp> timex wc -l hal.tmp > > 989702 hal.tmp > > > > real 11.45 > > user 9.77 > > sys 1.68 > > this is likely to be a hair faster: > > timex perl -ne '}print$.-1 ."\n";{' hal.tmp > > it's about 1% faster on my machine. > > if you've got Deparse and want to see what's going > on with these examples, run these commands... > > perl -MO=Deparse -lpe '}$_=$.;{' hal.tmp > perl -MO=Deparse -ne '}print$.-1 ."\n";{' hal.tmp > > -- > Steve Lane > -------------------------------------------------------------------------- > -- > To unsubscribe, please send email to majordomo@pm.org > with 'unsubscribe memphis-pm-list' in the body of the message. > -------------------------------------------------------------------------- > -- > ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From sheff at pobox.com Wed Sep 26 18:59:32 2001 From: sheff at pobox.com (Keith W. Sheffield) Date: Thu Aug 5 00:07:18 2004 Subject: [Memphis.pm] perl one liner In-Reply-To: Steve Lane's message of "Wed, 26 Sep 2001 13:43:41 -0400" References: <3BB213CD.EE152B2@zfx.com> Message-ID: >>>>> "Steve" == Steve Lane writes: > this is likely to be a hair faster: > timex perl -ne '}print$.-1 ."\n";{' hal.tmp The -1 will result in an incorrect answer. > it's about 1% faster on my machine. > if you've got Deparse and want to see what's going > on with these examples, run these commands... > perl -MO=Deparse -lpe '}$_=$.;{' hal.tmp > perl -MO=Deparse -ne '}print$.-1 ."\n";{' hal.tmp > -- > Steve Lane chomp is what's probably sucking up the extra time. I could have done it like: perl -pe '}$_="$.\n";{' or a few other variations I suppose. Is the 1% worth those three extra characters? =) ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ----------------------------------------------------------------------------