Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 rifling through the Monastery: (14)
As of 2014-08-01 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (33 votes), past polls