Pathologically Eclectic Rubbish Lister | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I've released a module named Array::AsHash which allows one to use references as hash keys (it actually does a lot more than this, but this is one of the features). Normally, this works fine:
It does this by checking the Scalar::Util::refaddr of the reference. However, this can fail if someone wants to override equality. In Python, you can get around this by overriding the __hash__() method of object. In Perl, we can't do this with unblessed references. Thus, the following will never succeed:
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. Things like the Test::More::is_deeply function or the useful Test::Deep module would be great, but they're tied to Perl's testing framework. Can anyone offer suggestions? 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. Cheers, New address of my CGI Course. In reply to Using references as hash keys by Ovid
|
|