Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Reference as a hash key

by AnomalousMonk (Archbishop)
on Aug 25, 2009 at 16:05 UTC ( [id://791122]=note: print w/replies, xml ) Need Help??


in reply to Reference as a hash key

It depends on just what you want to do with the keys of your hash.

As you see, all hash keys are stringified, so the keys can never again be used as references (the original references are unaffected). However, they are stringified uniquely because each reference has a unique address, so I see no problem with using the string representation to flag that a particular array has been handled.

Of course, if the referent of a reference is destroyed, the hash key corresponding to it is unaffected! You have to take care of this on your own. And remember: if references are destroyed and new ones created, old reference addresses may be re-used!

Actually, I think I would tend to use something like bluestar's suggestion in Re: Reference as a hash key: it's more general and flexible, probably more maintainable.

Updates:

  1. Added note about reference destruction.
  2. Added endorsement of bluestar's suggestion.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-25 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found