Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > References as hash keys (Srinivasan's "Advanced Perl Programming")?

Reply
Thread Tools

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

 
 
Adam Funk
Guest
Posts: n/a
 
      06-27-2006
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?
 
Reply With Quote
 
 
 
 
Adam Funk
Guest
Posts: n/a
 
      06-28-2006
On 2006-06-27, Jim Gibson <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#keys, Hash#values order question Ronald Fischer Ruby 0 08-23-2007 09:34 AM
hash.keys and hash.values Mage Ruby 14 08-15-2006 08:44 PM
Hash#values and Hash#keys order Alex Fenton Ruby 1 04-15-2006 05:45 AM
No Keys, nor other hash methods on multidimensional hash Xeno Campanoli Ruby 16 08-25-2005 07:04 AM



Advertisments