The autovivification module is pretty good for this kind of thing. Offers you the ability to simply switch off autovivification, warn about it, or croak. Rather than being tied to a particular hash, it's lexically scoped. And it's context-sensitive, so you could decide that 'store' operations are allowed to autovivify, like:
{
no autovivification qw(strict);
use autovivification qw(store);
my %hash;
$hash{foo}{bar}{baz} = 1; # autovivifies OK
delete $hash{fool}{bar}{baz}; # dies
}
If only autovivification weren't so tricky to type.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
|