in reply to Re: Doubt on defined-ness
in thread Doubt on defined-ness

The camel book lists the following (among others) as being equivalent:
while (defined($_=<STDIN>)) ... while ($_=<STDIN>) ... while (<STDIN>) ...
so I guess that only in the case of a while both the second and third form are equivalent to the first. This is not true for other boolean context like eg if.

Replies are listed 'Best First'.
Re^3: Doubt on defined-ness
by FunkyMonk (Bishop) on Jun 18, 2008 at 19:41 UTC
    It seems perl applies its magic test for definedness to any while that involves a filehandle (at least, I couldn't find a case where it didn't apply).
    $ perl -MO=Deparse -e 'while (<>) {} while ( <ARGV> ) {} while ( $_ = +<> ) {} while ( $x = <> ) {}' while (defined($_ = <ARGV>)) { (); } while (defined($_ = <ARGV>)) { (); } while (defined($_ = <ARGV>)) { (); } while (defined($x = <ARGV>)) { (); } -e syntax OK


    Unless I state otherwise, all my code runs with strict and warnings

      That's almost the limit. Anything more complex doesn't add a defined.

      >perl -MO=Deparse -e"while (<FILE> && foo()) {}" while (<FILE> and foo()) { (); } -e syntax OK