Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to check whether a hash is empty (has no keys)?

by ambrus (Abbot)
on Sep 05, 2011 at 10:32 UTC ( [id://924183]=note: print w/replies, xml ) Need Help??


in reply to How to check whether a hash is empty (has no keys)?

Just use the name of the hash in scalar context, such as

if (%foo) { # %foo has at least one key } else { # %foo has no keys }

If you want to be very explicit, you can also write

if (!!%foo) { ... }
or
if (scalar %foo) { ... }
or
if (0+%foo) { ... }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-24 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found