Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Test Presence of Data in Hash

by ikegami (Patriarch)
on Jul 20, 2009 at 20:43 UTC ( [id://781761]=note: print w/replies, xml ) Need Help??


in reply to Test Presence of Data in Hash

keys(%hash) returns false if the hash is empty. This is what you want. [Upd: Actually just %hash in scalar context is better if you don't need a count. ]

You'll never want to used defined on hashes and arrays. It reports on an unimportant internal property of those variables (whether or not some memory is allocated for data). This usage is even deprecated. Why aren't you using warnings?

$ perl -wle'my %a; print defined(%a)?1:0' defined(%hash) is deprecated at -e line 1. (Maybe you should just omit the defined()?) 0

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2025-07-12 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.