in reply to Re: reading several lines in a gulp
in thread reading several lines in a gulp

Same problem with moritz's first solution. Needs to handle eof conditions:

@lines = map {eof($file) ? () : scalar <$file>}, 1..10;

Replies are listed 'Best First'.
Re^3: reading several lines in a gulp
by Anonymous Monk on Apr 27, 2011 at 18:45 UTC
    In that case, defined-or operator imposes scalar context
    @lines = map { <$file> // () } 1 .. 10;

      Good use of //. Confirmed that it works:

      use strict; use warnings; my $fh = \*DATA; while (! eof $fh) { my @lines = map { <$fh> // () } 1..10; print "lines = " . @lines . "\n"; } __DATA__ line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10 line 11 line 12 line 13 line 14 line 15 line 16 line 17

      Outputs:

      lines = 10 lines = 7