in reply to Can you read a false value from a file?
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'.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Can you read a false value from a file?
by grantm (Parson) on Feb 11, 2006 at 09:39 UTC | |
by converter (Priest) on Feb 11, 2006 at 10:06 UTC | |
by ikegami (Patriarch) on Feb 11, 2006 at 09:58 UTC | |
by grantm (Parson) on Feb 11, 2006 at 10:03 UTC | |
by bart (Canon) on Feb 11, 2006 at 13:42 UTC |