Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by thelenm (Vicar)
on Nov 13, 2003 at 20:04 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found