Do you realize that
$h{a}{b}
is exactly the same thing as
$h{a}->{b}
and that is consists of two separate hash lookups? It's basically the same thing as
my $anon = $h{a};
$anon->{b}
You want %{ $h{a} }
to be a tied hash, but $h{a}
(FETCH
) returned a reference to an untied hash. Change it to return a tied hash.
$ perl -E'
sub DESTROY {}
sub FETCH { say "FETCH @_"; tie my %h, main; \%h; }
sub AUTOLOAD { say "$AUTOLOAD @_"; bless {} }
tie %h, main;
$h{a}{b}++;
'
main::TIEHASH main
FETCH main=HASH(0x8006c030) a
main::TIEHASH main
FETCH main=HASH(0x80071e28) b
main::TIEHASH main
main::STORE main=HASH(0x80071e28) b 2147952185