Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Hash of hashes assignment

by kennethk (Monsignor)
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 studying the Monastery: (7)
As of 2014-12-29 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls