Beefy Boxes and Bandwidth Generously Provided by pair Networks
DiBona XP is just a number  Re: Explaining Autovivication  by
throop (Chaplain) on Jun 12, 2008 at 04:20 UTC
( #691586=note: print w/ replies, xml ) Need Help??  in reply to
Explaining Autovivication  Autovivification saves a lot of
annoying effort. So if $quick is originally empty
$quick->{brown}->{fox} ->{$jumped} = 1 / $Lazy_dog; creates the
intermediate hashes so $quick can point to a hash-of-hashes-of-
hashes.  But autovivification can bite you / surprise you, too.
If you are testing a value (rather than setting it)
autovivification can still add entries to your hash. That is,
new keys. E.g., if you start with  $stateCityPopulation =
{Illinois => {Springfield => 116482}, Massachusets =>
{Springfield => 154082}, Missouri => {Springfield => 150797}}};
and then you foreach my $state (qw(Illinois Massachusets Ohio
Missouri)){ my $pop =
$stateCityPopulation->{$state}->{Springfield} || next;
$springfielders += $pop} Now when you look at keys %$stat