Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Truth and Falsehood

by haukex (Archbishop)
on Aug 17, 2019 at 10:12 UTC ( [id://11104613]=note: print w/replies, xml ) Need Help??


in reply to Re: Truth and Falsehood
in thread Truth and Falsehood

I've tested empty hashes on several perls here and they, like empty arrays, always appear to evaluate to zero as well. Is there a reason why you have expressed them differently here?

Just because that's what the Perl documentation says. perldata:

If you evaluate a hash in scalar context, it returns a false value if the hash is empty. If there are any key/value pairs, it returns a true value.

Replies are listed 'Best First'.
Re^3: Truth and Falsehood
by hippo (Bishop) on Aug 17, 2019 at 10:19 UTC

    I see - thank you. Interestingly the very next sentence in perldata is:

    A more precise definition is version dependent.

    which suggests that there may be some versions out there where the false value returned is not zero (or that there may be in future, intriguingly). I'll have to try to remember only to test the truth of empty hashes rather than their numerical value. :-)

      A more precise definition is version dependent. which suggests that there may be some versions out there where the false value returned is not zero

      That sentence was introduced along with the change that scalar(%hash) returns the same thing as 0+keys(%hash) instead of the bucket counts, so I suspect that's what it is referring to.

      But anyway, when the Perl documentation says "a false value" or "false", I don't make any assumptions of which of the possible false values it'll return :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-03-28 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found