Re: perlfaq4: multiple answers affected

[email protected] (Smylers) Mon, 10 Oct 2005 21:22:13 GMT
Newsgroups perl.perlfaq.workers
Message-ID <[email protected]>
_brian_d_foy writes:

> * How can I use a reference as a hash key?
>    + I updated the answer to explain why you shouldn't.

The answer (both before and after your change) presumes that the user
wishes to be able to get to the original reference from the hash key,
and that trying to use the reference directly (stringifying it) is bad.

But if you only every need to go in the other direction (somebody gives
you a reference and you store some information about it; later you get
given that same reference and you wish to retrieve the information you
stored earlier), then I think that stringifying a reference is
acceptable.

The answer should include this, or the question should be phrased more
tightly so as not to put off people wanting to do the above.

In 'Perl Best Practices' Damian (p 330) recommends using
Scalar::Util::refaddr or similar instead of just stringifying references
directly.  I guess this avoids being confused by a reference changing
which class it is blessed into, or being in a class with overloaded
stringification.

Smylers
-- 
May God bless us with enough foolishness to believe that we can make a
difference in this world, so that we can do what others claim cannot be done.