Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Making a failed hash lookup return something other than undef

by thelenm (Vicar)
on Nov 13, 2003 at 20:04 UTC ( #306917=note: print w/ replies, xml ) Need Help??


in reply to Making a failed hash lookup return something other than undef

The code you posted has a problem when a hash entry exists but has a false value like 0 or undef. The straightforward way to test whether a hash entry exists is to use exists, e.g.:

my $var = exists $hash{'key'} ? $hash{'key'} : "unknown";

This is not particularly pretty, but works, and I don't know of a more succinct way to do the same thing.

-- Mike

--
XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
-- grantm, perldoc XML::Simpler


Comment on Re: Making a failed hash lookup return something other than undef
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2015-07-30 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls