develooper Front page | perl.perl5.porters | Postings from September 2011

Re: [perl #94350] definition of truthiness in the perldocs

Thread Previous | Thread Next
Eric Brine
September 17, 2011 21:44
Re: [perl #94350] definition of truthiness in the perldocs
Message ID:
On Fri, Jul 8, 2011 at 1:12 AM, <>wrote:

> # New Ticket Created by
> # Please include the string:  [perl #94350]
> # in the subject line of all future correspondence about this issue.
> # <URL: >
> This is a bug report for perl from,
> generated with the help of perlbug 1.39 running under perl 5.14.1.
> -----------------------------------------------------------------
> [Please describe your issue here]
> So I was looking for the official definition of "truth" in the perldocs.
> perldata says:
> | A scalar value is interpreted as TRUE in the Boolean sense if it is not
> | the null string or the number 0 (or its string equivalent, "0").
> perlsyn says:
> | The number 0, the strings C<'0'> and C<''>, the empty list C<()>, and
> | C<undef> are all false in a boolean context. All other values are true.

The most concise and accurate definition I've come across is:

Anything that stringifies to "" or "0" is a false value

This definition covers objects with overrides. Examples can be appended.

> perlsyn claims the empty list is false, which doesn't even make sense.
> There are no lists in
> scalar context.

There's no such thing as a list *value* in scalar context, but the list
*operator* can definitely be used in scalar context.

my $x = (1,2,3);

Booleans are scalars. Therefore you can't have an "empty list"
> in boolean context (C<()> simply evaluates to C<undef> but I don't know if
> that's documented anywhere).

True, "()" evaluates to undef. But that's false, so what's the issue?

- Eric

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About