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.