http://qs321.pair.com?node_id=853685


in reply to Re: File Reading and Closing confusion
in thread File Reading and Closing confusion


Actually, a crucial difference is that while(<FH>){...} gets interpreted by Perl as:
while (defined($_ = <FH>)) { ... }

which effectively ends the while loop once there are no more lines to be read from the filehandle. With $line=<FH>, we need to check for defined-ness.


Another way:
my @lines = do { local @ARGV = $file; <> };