Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Checking if hash value exists without implicitly defining it

by trizen (Hermit)
on Feb 14, 2013 at 20:18 UTC ( #1018780=note: print w/replies, xml ) Need Help??


in reply to Checking if hash value exists without implicitly defining it

Here is a recursive check, without autovivification.
sub _exists { my ($hash, @keys, @exists) = @_; if (exists $hash->{$keys[0]}) { my $key = shift @keys; push @exists, 1, _exists($hash->{$key}, @keys); } return @exists; } sub exists_keys { return &_exists == $#_ ? 1 : (); } my %hash; #$hash{a}{b}{c} = undef; if (exists_keys(\%hash, qw(a b c))) { print "Exists.\n"; } else { print "Doesn't exists.\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018780]
help
Chatterbox?
[Discipulus]: thanks.. a more perlish solution?
[Corion]: Discipulus: I've looked for something but never found anything good
Corion looks at the SVG. If the different regions have IDs, then you can colorize the map by providing a CSS file with the colors.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2017-03-23 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.