Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Hash of hashes assignment

by kennethk (Abbot)
on Apr 12, 2013 at 15:01 UTC ( #1028390=note: print w/ replies, xml ) Need Help??


in reply to Hash of hashes assignment

In the first statement, you are creating an anonymous hash reference, storing in it the contents of the hash %hash via list assignment, and then storing that reference in %hashOfHashes with key value $value.

In the second, you have a scalar assignment of %hash to %hashOfHashes with key value $value. In scalar context, a hash returns information about how many buckets are available and filled. If you have a hash with 4 key-value pairs, you might get 4/8 returned -- 8 buckets allocated with 4 filled.

The third permutation here, and maybe what you want, would be $hashOfHashes{ $value } = \%hash; This stores a reference to %hash in %hashOfHashes with key value $value.

For more info, see perldsc. Also relevant: perldata, perlref, perlreftut, perllol...


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: Hash of hashes assignment
Select or Download Code
Re^2: Hash of hashes assignment
by Anonymous Monk on Apr 12, 2013 at 16:31 UTC
    Thanks you so much. This is why I love the Perl community! Perfect explaination, thanks. I would normally use a hashref myself I was trying to figure out what this code was doing.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2015-07-07 12:26 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 (88 votes), past polls