I was referring to being wary when $line=<FH> is used on its own.
Yes, but while takes care of that - and we/you were talking about a while loop, weren't you?
1. while (<>) {
...
which is Perl short-hand for the more explicitly written version:
1. LINE: while (defined($line = <ARGV>)) {
...
But of course,
We see that there is a possibility that a line read ($line3 in this case) may return undef.
- if you read past EOF, for instance. Then readline returns undef:
open(FH, "<", "a.txt") or die $!;
my $line1 = <FH>;
my $line2 = <FH>;
print "eof!\n" if eof FH;
my $line3 = <FH>;
close FH;
__END__
eof!
That's what I meant: we need to be wary that a line read will not always return defined.
That's exactly the condition when both the while($line = <FH>) { } and while(defined($line = <FH>)) { } loops terminate, so there's no difference in a while loop.