[TriLUG] Perl question. . .

Michael Peters mpeters at plusthree.com
Tue Feb 17 15:22:55 EST 2009


Michael Peters wrote:
> Michael Peters wrote:
> 
>>      if( $line++ == $pick ) {
> 
> Actually that should probably be "++$line == $pick". Since most people think of the first line as 
> #1, not #0.

Wow, I really should have actually run that code first :) Here's a better version:

]$ cat bin/pick
#!/usr/bin/perl
my $pick = shift;
my $count = 0;
while (my $line = <>) {
     if( ++$count == $pick ) {
         print $line;
         exit(0);
     }
}

-- 
Michael Peters
Plus Three, LP




More information about the TriLUG mailing list