Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Hash Printing reveals Hash Memory Location

by tobyink (Abbot)
on Feb 03, 2012 at 01:04 UTC ( #951573=note: print w/ replies, xml ) Need Help??


in reply to Hash Printing reveals Hash Memory Location

You have:

my %words = {};

You want:

my %words = ();

Or better yet:

my %words;

Essentially in that first line, you're adding an entry to the hash where the key is a reference to an anonymous second hash, and the value is undefined. Because you can't use references as hash keys, the reference is stringified (which looks like a memory location).

In other words, my %words = {}; is basically a shorthand for:

my %words; my $ref_to_anon_hash = {}; $words{ $ref_to_anon_hash } = undef;


Comment on Re: Hash Printing reveals Hash Memory Location
Select or Download Code
Replies are listed 'Best First'.
Re^2: Hash Printing reveals Hash Memory Location
by perlStuck (Sexton) on Feb 03, 2012 at 01:08 UTC

    Ah. Thank you!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2015-07-29 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls