http://qs1969.pair.com?node_id=500598


in reply to Using references as hash keys

Ordinarily, this is fine. However, if we only care about the values a reference contains and not whether or not it's the same reference, we're stuck. I'd like to be able to pass the constructor a coderef which will determine equality of references beyond simply comparing their addresses.

Well, if you're using Perl's native hashes behind the scenes then you could just use Storable... maybe something like:

use Storable; sub identity_of { my $thing = shift; local $Storable::canonical = 1; return ref $thing ? Storable::freeze( $thing ) : $thing; }; my $array = Array::AsHash->new({ array => [ [1,2,3] => 'Ovid' ], hash_on => \&identity_of, });

If you want to go hard-core implement your own hashing behind the scenes and pass hash and equality functions :-)

For those wondering why I want to do this, I don't need this myself (yet), but I'm creating a flexible general purpose tool for folks and I'd like to give them the ability to override behavior as needed.

What was it you said recently about YAGNI?