Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: using references as keys in a hash.

by seattlejohn (Deacon)
on Feb 23, 2003 at 02:15 UTC ( [id://237841]=note: print w/replies, xml ) Need Help??


in reply to using references as keys in a hash.

When you stringify a reference, it no longer is a reference -- it's just a plain old string that happens to contain a human-readable representation of an address and a data type. So the code above is doing just what it would do if your initial hash assignment read:
%hash = ("ARRAY(0x80fbb0c)" => "STUFF");
If you turned on strict, you'd be warned that a string can't be used as an array reference.

Hash keys must be strings, not references. If you want to "dereference" something, you probably should be storing the reference itself as a hash value, so you can use it directly and not need to dereference it in the first place.

        $perlmonks{seattlejohn} = 'John Clyman';

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-16 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found