in reply to reading several lines in a gulp

my $several = ...; my @lines; push @lines, $_ while @lines < $several && defined($_ = <$file>);

Replies are listed 'Best First'.
Re^2: reading several lines in a gulp
by John M. Dlugosz (Monsignor) on May 01, 2011 at 16:31 UTC
    Interesting, by using the count-up of the scalar @lines instead of counting down of $count it is naturally proof against funny (negative) values of $count and works correctly for an initial value of zero.

    If scalar @lines is efficient and "free" (it knows the size anyway) it might even be faster than incrementing $count.