Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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?
[LanX]: Eily: nit picking: Assurancetourix!
[karlgoethebier]: We also have Costa Nix
[Eily]: indeed
[LanX]: I like http://www.comedix .de/lexikon/db/ nihamavasah.php = never have we water and http://www.comedix .de/lexikon/db/ erindjah.php = Air India xD
[LanX]: work!
[LanX]: thats very strange, I try to change two columns to "unique" and MySQL is complaining even that the data is already unique ???
[karlgoethebier]: Angie Singing

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2017-05-24 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?