I forgot to mention that your loop will not execute if a line evaluating to false in boolean context is read
Actually, no - if you read the perlop 'I/O Operators' entry carefully, you'll find that using <FILEHANDLE> inside a while (or for(;;)) construct is treated specially - a defined test is done for you, to avoid exactly the problem you mention...
I case you're too lazy to look it up, I quote:
In these loop constructs, the assigned value (whether assignment is automatic or explicit) is then tested to see whether it is defined. The defined test avoids problems where line has a string value that would be treated as false by Perl, for example a "" or a "0" with no trailing newline. If you really mean for such values to terminate the loop, they should be tested for explicitly:
while (($_ = <STDIN>) ne '0') { ... } while (<STDIN>) { last unless $_; ... }
In other boolean contexts, "<filehandle>" without an explicit "defined" test or comparison elicit a warning if the "use warnings" pragma or the -w command-line switch (the "$^W" variable) is in effect.
HTH
--In reply to Re: Re: undefined question
by edan
in thread undefined question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |