Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 romping around the Monastery: (13)
As of 2014-09-30 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (364 votes), past polls