http://www.perlmonks.org?node_id=306917


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