in reply to Logical expression evaluation

In Perl, the logical values are typically 1 for truth, and undef for falsehood. When treated as a number, undef == 0, when treated as a string, undef eq '', all of which are treated as a false in boolean condition checks.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re^2: Logical expression evaluation
by ikegami (Patriarch) on Jul 27, 2005 at 16:26 UTC
    As mentioned earlier in this thread, Perl uses "" for false. It does not use undef.
    $i = undef; print(defined($i) ? "[$i]" : 'undef', "\n"); $i = !1; print(defined($i) ? "[$i]" : 'undef', "\n"); __END__ output ------ undef []
        And nowadays, you can have the magic of dualvars for your own evil plots applications, using dualvar() from Scalar::Util.

        BTW another typical magical dualvar value is $!, which returns an error message as a string, and an error number as a number. For example:

        local $\ = "\n"; $! = 3; # error number print $!; # error message print 0+$!; # error number