Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Detecting an undefined hash key

by JavaFan (Canon)
on Oct 01, 2008 at 10:33 UTC ( [id://714773]=note: print w/replies, xml ) Need Help??


in reply to Detecting an undefined hash key

You seem to be mixing up terms.

Hash keys are used as an index in the hash. Hash keys are always strings, and are always defined. There's no such thing as an undefined hash key.

Having said that:

if (exists $hash{key}) { ... } # True if there's a value for 'ke +y' if (defined $hash{key}) { ... } # True if there's a value for 'ke +y' and the value is defined. if ($hash{key}) { ... } # True if there's a value for 'ke +y' and the value is true.
defined is the test to use to test whether something is defined. To test the existance of a hash key, use exists.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2025-12-05 18:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (85 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.