Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How do you check if a key exists without creating it ?

by wind (Priest)
on Oct 06, 2012 at 08:43 UTC ( #997603=note: print w/ replies, xml ) Need Help??


in reply to How do you check if a key exists without creating it ?

You're just falling into autovivification. Check for existence of the lower level first if you don't want it autocreated:

use Data::Dumper; $x = {}; 1 if ( $x->{Y} && exists $x->{Y}{X} ) ; 1 if ( $x->{Z} && defined $x->{Z}{A} ); print Dumper $x;


Comment on Re: How do you check if a key exists without creating it ?
Download Code
Replies are listed 'Best First'.
Re^2: How do you check if a key exists without creating it ?
by exilepanda (Monk) on Oct 06, 2012 at 11:34 UTC
    haha.. yes, lesson just learned! Thank you very much! =)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (18)
As of 2015-07-30 18:46 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 (273 votes), past polls