Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Strange behaviour reading from hashref stored in array

by Random_Walk (Parson)
on Feb 16, 2009 at 15:36 UTC ( #744095=note: print w/ replies, xml ) Need Help??


in reply to Strange behaviour reading from hashref stored in array

As moritz says this is auto vivification. There is a way you can test if a key exists without the side effect of creating it

my @a = ( {}, {}, {} ); print $a[3]{foo} if exists $a[3] and exists $a[3]{foo}; # or if you only want to ensure you don't expand @a # print $a[3]{foo} if exists $a[3]; print scalar @a . "\n";

not the most attractive looking code though

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!


Comment on Re: Strange behaviour reading from hashref stored in array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2015-07-28 06:41 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 (252 votes), past polls