On Tue, Feb 01, 2005 at 12:41:27PM -0500, Ronald J Kimball wrote:
> On Tue, Feb 01, 2005 at 05:34:18PM -0000, Steve Peters via RT wrote:
> 
> > While I agree that an explanation of why "print !!0" doesn't work isn't
> > needed (take a look at Devel::Peek.  It's your friend!), I was unable to
> > find actual documentation as to what values actually evaluate to TRUE or
> > FALSE in Perl.  There is some pasing references to "", 0 and 1 in
> > perlop.pod.  perlfaq4 deals with hashes.  The rest, as I've painfully
> > learned in the past, are undocumented and a common source of bugs for
> > beginners.
> 
> perldoc perlsyn:
> 
>   Truth and Falsehood
> 
>   The number 0, the strings '0' and '', the empty list "()", and "undef"
>   are all false in a boolean context. All other values are true.
> 
> Is that sufficient?  I'm not sure what you mean by "the rest".

The fact that the value returned for "false" is the string "", but the
number 0:

$ perl -wle 'print ">$_< ", $_ + 0 foreach 1==1, 1!=1'
>1< 1
>< 0

And note that it's a dual value - it's not actually a regular empty string:

$ perl -wle 'print ">$_< ", $_ + 0 foreach "1", ""'
>1< 1
Argument "" isn't numeric in addition (+) at -e line 1.
>< 0

Nicholas Clark

Reply via email to