in reply to Re: Autovivification with hash of hashes
in thread Autovivification with hash of hashes
update:use strict; #this basically disallows symblic ref use warnings; my %foo; $foo{bar} = "key bar's value"; #now you made $foo{bar} EXISTS, there i +s no need for auto-vivification to create it any more. MOST IMPORTANT +LY, this can be a symblic reference depending on how you use it, cont +inue... if(exists($foo{qux})) { print "\$foo{qux} exists"; } if(ref $foo{bar} eq 'HASH' && exists($foo{bar}{baz})) {#Here you are s +trongly suggesting a symblic reference. As for the code, the part bef +ore && obviously evaluate to false, so that exists after && will be e +valuated, but no auto-vivfication here, as $foo{bar} exists any way print "\$foo{bar}{baz} exists\n";#will not print as there is no $f +oo{bar}{baz} } if(exists($foo{bar})) {#yes print "\$foo{bar} popped into existence\n";#print out, but not pop +ped into existence, it is actually created by you } #the following is added by me $foo{bar}{baz} = 1; #violates strict refs, error, because you set $foo +{bar} to a string earlier. There is no way to create $foo{bar}{baz} i +n this context, unless you turn off use strict("refs")
"And the latter is exactly what he's talking about protecting against by using ref."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Autovivification with hash of hashes
by Aristotle (Chancellor) on Jan 26, 2003 at 05:34 UTC | |
by trs80 (Priest) on Jan 26, 2003 at 23:14 UTC |