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

Re: I want to check if a particular hash exists or not and not just the key.

by stevieb (Canon)
on Aug 17, 2015 at 13:16 UTC ( [id://1138884]=note: print w/replies, xml ) Need Help??


in reply to Non existent Hash and error"not a hash refernece at perl line"

Check for exists:

if (! exists $hash{$key}){ ... next; }

In the above, it's possible to just say if (! $hash{$key}), but if the hash key's value has something like 0 or anything else false (or undef), the if will be false.

Check if hash key is another hash:

if (! ref $hash{$key} eq 'HASH'){ ... next; }

Now, with that said, you're probably best off showing us a piece of your structure and the code that accesses it. Many times, warnings like this are thrown due to the code accessing the structure is doing something we don't expect, and other times it may be because we are misunderstanding what the structure really is in the first place.

-stevieb

Re-parented this (my own) node from considered duplicate I want to check if a particular hash exists or not and not just the key.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-18 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found