in reply to Re: error printing all text in text file
in thread error printing all text in text file
Assuming that the last line is terminated properly, after all data is read from the filehandle, $line will be undefined. chomp won't like that and will barf.
Now if the last line of the file is not terminated, an even more insidious thing can happen. That last line will be ignored because chomp does not remove any characters from that line.
So, don't use this construct.
here is proof:
use strict; use warnings; $|=1; my $data = <<END; asdf fjfjf 324 0 2345 2wefrwef END #chomp $data; #toggle on/off to see results open my $fh, "<", \$data or die "$!"; while (chomp (my $line = <$fh>)) { print $line; } __END__ asdf fjfjf324023452wefrwefUse of uninitialized value $line in chomp at + testchompWhile.pl line 15, <$fh> line 5. asdf fjfjf32402345
|
|---|