Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Answer: How do I find out if a hash is empty?

by mojotoad (Monsignor)
on Jun 12, 2002 at 05:14 UTC ( #173735=categorized answer: print w/replies, xml ) Need Help??

Q&A > hashes > How do I find out if a hash is empty? - Answer contributed by mojotoad

Beware the Ties of March!!!

In my innagural post I pointed out that a hash in scalar context will not behave as expected when tied, although it's tasty syntax: if (%my_hash) { ... do stuff ... }

I feel that's a bug and should be addressed.

As a bulletproof workaround, always use keys in scalar context thusly: if (scalar keys %my_hash) { ...do stuff... }

Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2019-10-16 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?