in reply to Re^2: Best Hash Practices?
in thread Best Hash Practices?
I know what you mean but the syntax you're proposing is not feasible, since it's the arrow operator which is autovivifying!
isDefined($h{"a"}->{2}->{c}->{4});
So when isDefined comes into action it's already to late!
Anyway one can easily extend the syntax of my approach to make it "smoother"!
xdefined(%h => qw/a 2 c 4/)
or
xdefined(%h => "a",2,"c",4)
But IMHO (within the boundaries of perl) the syntactically "prettiest" way to go would be to use a tied copy of your hash, like this you may be able to write
novivi(%h)->{a}{2}{c}{4}
%h2=novivi(%h) should be an empty hash with a hash-tie which mirrors safely the structure of %h.
Such that $h2{a} is only be defined iff $h{a} is defined and all the automatically vivified structures in $h2{a}{2}{c}{4} are automatically tied hashes bound to the corresponding structures in %h.
Well ... I think this is feasible, BUT should come with a significant performance penalty compared to my first approach, since ties are expensive.
Cheers Rolf
|
|---|