Consider this:
$ hexdump -C foo 00000000 61 0a 30 |a.0| 00000003 $ perl -wle 'print "read line" while (my $x = <>)' foo read line read line $
I have a file foo here with an 'a', a newline, and a '0' - no trailing newline.
I'd expect just one line of output, because 0 is false. But why am I getting two lines? That doesn't seem to be logical to me.
So I modified my test scrpt a bit:
$ perl -MDevel::Peek -wle 'while (my $x = <>){ print "read line"; pri +nt "and its true" if $x }' foo read line and its true read line
So, the second line evaluates to true in the while-condition, but not in the following if-condition. Is there some kind of special magic? If yes, where is it documented?
Update ok, got it. Thank you all. I didn't realize it works for arbitrary variable names, and thought that $_ was special cased.
In reply to Re^2: Doubt on defined-ness
by moritz
in thread Doubt on defined-ness
by waldner
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |