I use dynamic multi-level hashes from which I read data, but also write data.
A common mistake for me is access to non-existent keys (typos, db versions, etc.). I get undefthat apply to other parts and cause problems. I would like diewhenever I try to read a non-existent key, but I am still allowed to add new keys.
So the desired behavior:
my %hash;
$hash{A} = 5;
print $hash{A}, "\n";
print $hash{X}, "\n";
$hash{B}{C}{D} = 10;
print $hash{B}{C}{X}, "\n";
I posted a similar question earlier and got great answers. I especially like the accepted one, which allows you to use the usual hash syntax. The only problem is that I'm not sure how easy it is to generalize this to deep hashes, as in the example above.
ps I think this feature is really useful, and I wonder if I am missing something because it is not very popular. Maybe it is not uncommon to read / write from / to the same hash?
source
share