in reply to weird reference bug with perl 5.005_03

Looks like a bug in Perl but I can't say I blame Perl much for this one!

What you do above is take a reference to a non-existant hash value and then later try to use that as an anonymous hash in order to take another reference to a non-existant hash value. Then you assign to the last reference and expect all of the previous non-existant hash values to get autovivified into anonymous hashes!! I'm amazed it even works as well as it does!

This line: deref ($_[0]->{$1}, $_[1]); calls deref with a first argument of undef. Note that that line doesn't assign to $_[0]->{$1} so it doesn't autovivify anything at that point. Later you use that undef in that same line to get another undef. You are lucky that at this point Perl manages to autovivify the previous undef into an anonymous hash. It appears that in Perl 5.005 and 5.004, this isn't done perfectly so strange things can happen after this, somewhat at random (based on my testing).

You can fix the problem by removing the need to autovivify:

sub deref { return \$_[0] unless $_[1] =~ s/^-([\w\._]+)//; $_[0]->{$1} ||= {}; # Vivify an anonymous hash if needed. deref ($_[0]->{$1}, $_[1]); }

        - tye (but my friends call me "Tye")