grantm has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Can you read a false value from a file?
by ikegami (Patriarch) on Feb 11, 2006 at 09:23 UTC | |
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 |