Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Anonymous Monk
on Mar 31, 2016 at 07:54 UTC ( [id://1159183]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^6: What could make "()" a good value for boolean false?
by ikegami (Patriarch) on Apr 01, 2016 at 15:55 UTC

    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://1159183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2026-01-19 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (122 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.