Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Tuesday December 03, 2002
02:10 PM

Skipping leading lines of input

[ #9249 ]

I have never had much use for the comma operator in scalar context until I needed to skip the first two lines of file but grab the third.

Normally I would read the leading lines in void context.

<FILE>;
<FILE>;
my $line = <FILE>;

I have always thought that was really ugly, but now I have something better. The comma operator reads its left argument, throws away the result, then reads its right argument and returns the result.

my $line = ( <FILE>, <FILE>, <FILE> );