Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028390]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-03-24 08:46 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (297 votes). Check out past polls.