Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Using references as hash keys

by xdg (Monsignor)
on Oct 16, 2005 at 12:04 UTC ( [id://500549]=note: print w/replies, xml ) Need Help??


in reply to Using references as hash keys

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.

You could just extract the relevant code from is_deeply and provide a "deep_references" option in the constructor as to whether references should be compared by their refaddr or by their contents. For this, you'll need to keep a copy of the references, too, hashed on their refaddrs to be able to retrieve them for comparison. (I think you'll want a regular reference, not weak one -- and the semantic will then be that storing something under a reference increments the refcount for that reference.)

The other way to go is more like tye's suggestion around the hashing function, so if you want deep references, you freeze their contents into a string and hash on that.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://500549]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-24 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found