jktstance has asked for the wisdom of the Perl Monks concerning the following question:
If I open a file for reading, open FP, "<", "test.txt"; then the following should loop over each line and stop when <FP> is false:
However, what if the file test.txt has a single line in it that is simply "0"? How come the while loop continues? Shouldn't it stop because <FP> returns 0, which is false? My only guess as to why it continues is because <FP> actually returns 0 and a newline character.while (<FP>) { ... }
From this wonderful resource, it says that the while loop only stops on undef. I can't seem to find official documentation as to why the conditional changes from a Boolean to defined() in the presence of the diamond operator.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: while (<FP>) conditionals
by davido (Cardinal) on Feb 04, 2014 at 22:25 UTC | |
|
Re: while (<FP>) conditionals
by Athanasius (Archbishop) on Feb 05, 2014 at 04:48 UTC | |
by jktstance (Novice) on Feb 05, 2014 at 14:46 UTC | |
by SuicideJunkie (Vicar) on Feb 05, 2014 at 15:31 UTC | |
by choroba (Cardinal) on Feb 05, 2014 at 16:26 UTC | |
by jktstance (Novice) on Feb 05, 2014 at 20:28 UTC | |
by Athanasius (Archbishop) on Feb 05, 2014 at 16:48 UTC | |
by jktstance (Novice) on Feb 05, 2014 at 20:27 UTC |