in reply to Re: Use a hashref as a key in another hashref?
in thread Use a hashref as a key in another hashref?

The problem with this is that reference addresses are not guaranteed to be unique. If a hash is destroyed (e.g. has gone out of scope), then its address can be re-used when a new hash is created. On my machine at least, the following prints the same reference address twice:

{ my $x = { foo => 1 }; print $x, "\n"; } { my $y = { bar => 2 }; print $y, "\n"; }
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^3: Use a hashref as a key in another hashref?
by LanX (Saint) on Jun 05, 2014 at 10:21 UTC
    Sure that's why you have to keep the original unweakend ref for each key!

    The keystrings are guaranteed to be unique as long as the ref count is positive.

    And as soon as a hash entry is deleted the shadow entry should be deleted too.

    This could best be synchronized with a tied hash or a dedicated object.

    And that structure can be safely passed around then.(CPAN to rescue! ;)

    But as I already said this is rarely worth the trouble, avoiding refs as keys is the better design decision.

    Cheers Rolf

    (addicted to the Perl Programming Language)