in reply to Re^3: File Reading and Closing confusion
in thread File Reading and Closing confusion
I was referring to being wary when $line=<FH> is used on its own. To illustrate:
We see that there is a possibility that a line read ($line3 in this case) may return undef. That's what I meant: we need to be wary that a line read will not always return defined.
$ perl -e 'print "with_ending\nno_ending"' > a.txt $ perl -MData::Dumper open(FH, "<", "a.txt") or die $!; my $line1 = <FH>; my $line2 = <FH>; my $line3 = <FH>; close FH; $Data::Dumper::Useqq = 1; print Dumper [$line1, $line2, $line3]; __END__ $VAR1 = [ "with_ending\n", "no_end", undef ];
We see that there is a possibility that a line read ($line3 in this case) may return undef. That's what I meant: we need to be wary that a line read will not always return defined.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: File Reading and Closing confusion
by shmem (Chancellor) on Aug 09, 2010 at 09:30 UTC | |
by repellent (Priest) on Aug 09, 2010 at 15:37 UTC |
In Section
Seekers of Perl Wisdom