Just like
while (<FH>)
is equivalent to
while (defined($_ = <FH>))
while (my $line = <FH>)
is equivalent to
while (defined(my $line = <FH>))
This can be demonstrated using the following program.
open(my $in, '<', 'file.dat') or die("Unable to open input file: $!\n"); while (my $line = <$in>) { if ($line) { print("true\n"); } else { print("true for 'while', but false for 'if'\n"); } }
outputs
true for 'while', but false for 'if'
when a file.dat contains the lone character zero (0).
By the way, overloading aside, only the following evaluate to false: numerical expressions evaluating to zero, the string '0', the empty string '' and the undefined value. 0.0 and 0E0 are the same as 0, but neither '0.0' nor '0E0' are the same as '0'.
In reply to Re: Can you read a false value from a file?
by ikegami
in thread Can you read a false value from a file?
by grantm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |