Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: What could make "()" a good value for boolean false?

by Your Mother (Archbishop)
on Mar 31, 2016 at 03:54 UTC ( [id://1159180]=note: print w/replies, xml ) Need Help??


in reply to Re^3: What could make "()" a good value for boolean false?
in thread What could make "()" a good value for boolean false?

…Maybe this is what is meant?

perl -le 'sub bingo { return 0 }; @a = bingo(); print @a ? "True" : "F +alse"' True

Replies are listed 'Best First'.
Re^5: What could make "()" a good value for boolean false?
by Anonymous Monk on Mar 31, 2016 at 07:54 UTC

    Yes (although strictly speaking, that's an array in scalar context), and also

    $ perl -wMstrict -le 'sub foo { print wantarray?"list":"scalar"; return 0; }; print( (()=foo()) ? "true" : "false" );' list true

    (although strictly speaking, that's a list assignment in scalar context). But there's also perlsyn (emphasis mine):

    The number 0, the strings '0' and "", the empty list (), and undef are all false in a boolean context. All other values are true.

      That doesn't check if () is true or false. Change it to ($x) or @a and you'll get exactly the same result. That check if = is true or false, which check the number of elements on the **RHS** of =.

      That passage is poorly worded, leading to people like you quoting it as it says something other than it says. When it says (), when it says "()", it's actually referring to "the value returned by () in scalar context, which is the same thing as saying undef. () is not a value. It shouldn't list one of the many many operator that can return something false in scalar context.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1159180]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-26 05:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found