Skipping leading lines of input

brian_d_foy on 2002-12-03T19:10:21

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.

;
;
my $line = ;


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 = ( , ,  );