According to the perlsyn (Perl Syntax) man page ...
while (<FH>) {
... is equivalent to ...
while (defined($_ = <FH>)) {
Conventional Perl wisdom has it that if you're not using $_, but assigning to a named variable ...
while (my $line = <FH>) {
... then you should write it like this ...
while (defined(my $line = <FH>)) {
The reason being, you only want the loop to terminate at the end of file (<FH> will return undef) and not when you read a line that happens to evaluate to false.
My question is: Assuming $/ still contains the default value, is it possible to read a line which evaluates to false?
A quick experiment shows that the string "0" is false, but "0\n" is true. Can anyone give a string with a trailing newline that evaluates to false in a boolean context?
And, if changing $/ does make it possible, what would I have to change it to?
In reply to Can you read a false value from a file? by grantm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |