Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   References as hash keys (Srinivasan's "Advanced Perl Programming")? (http://www.velocityreviews.com/forums/t898740-references-as-hash-keys-srinivasans-advanced-perl-programming.html)

Adam Funk 06-27-2006 03:27 PM

References as hash keys (Srinivasan's "Advanced Perl Programming")?
 
Srinivasan's "Advanced Perl Programming" (1997) says

--> Perl requires hash keys to be strings, so when you use a
--> reference as a key, Perl uses the reference's string
--> representation.... But when you later retrieve the key from
--> this hash, it will remain a string and will thus be unusable
--> as a reference. It is possible that a future release of Perl
--> may lift the restriction that hash keys have to be strings,
--> but for the moment, the only recourse ... is to use the
--> Tie::RefHash module.... There are few algorithms that
--> require references to be used as hash keys and fewer still
--> that cannot live with this restriction.

Is this still (5.8.x) the case? What practical effect does this
limitation have?

Adam Funk 06-28-2006 10:15 AM

Re: References as hash keys (Srinivasan's "Advanced Perl Programming")?
 
On 2006-06-27, Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:

> The practical effect is that if you do want to use references as hash
> keys, you can, but if you need to dereference the references, you can't
> store the references only in the hash as keys unless you use the
> Tie::RefHash module. Without using that module, you need to store the
> references separately from the hash, in an array for example, and
> dereference those values and use them as keys to the hash.
>
> Like the documents say, this is rarely necessary. I only contemplated
> doing it once in many years of Perl programming, and, although it
> worked, I soon found it unnecessary and abandoned it.


Interesting; thanks.


All times are GMT. The time now is 04:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.