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

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

Thread Previous | Thread Next
From:
Eric Brine
Date:
September 17, 2011 21:44
Subject:
Re: [perl #94350] definition of truthiness in the perldocs
Message ID:
CALJW-qHXO_sRm8+kdzjYWYYZ_f8d95soym_eKs6cq1bUv+8Dmw@mail.gmail.com
On Fri, Jul 8, 2011 at 1:12 AM, l.mai@web.de <perlbug-followup@perl.org>wrote:

> # New Ticket Created by  l.mai@web.de
> # Please include the string:  [perl #94350]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=94350 >
>
>
>
> This is a bug report for perl from l.mai@web.de,
> 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About