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
Re: References as hash keys (Srinivasan's "Advanced Perl Programming")?
On 2006-06-27, Jim Gibson <email@example.com> 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.
|All times are GMT. The time now is 11:36 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.