in reply to How does the while works in case of Filehandle when reading a gigantic file in Perl
Since while evaluates the condition in scalar context and the line input operator (<>) returns the next line of input (or undef on end-of-file) in scalar context, that code processes file line by line.
On the other hand, when <> is evaluated in list context, it returns a list of all lines (they all go the memory!) from file.
while (<$fh>) { # Read line by line; generally preferred way (especi +ally for large files) print "The line is: $_"; } foreach (<$fh>) { # Read all lines at once print "The line is: $_"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How does the while works in case of Filehandle when reading a gigantic file in Perl
by locked_user sundialsvc4 (Abbot) on Jan 30, 2015 at 15:00 UTC | |
by Anonymous Monk on Jan 30, 2015 at 15:22 UTC | |
by CountZero (Bishop) on Jan 30, 2015 at 20:48 UTC | |
by locked_user sundialsvc4 (Abbot) on Jan 30, 2015 at 22:14 UTC |