in reply to Hash of hashes assignment

Use Data::Dumper to visualize complex data structures.
use strict; use warnings; use Data::Dumper; my %hash = ( Sun => 'day', Moon => 'night', ); my %hoh; $hoh{correct} = { %hash }; $hoh{wrong} = %hash; print Dumper \%hoh;

Output:

$VAR1 = { 'correct' => { 'Moon' => 'night', 'Sun' => 'day' }, 'wrong' => '2/8' };
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Hash of hashes assignment
by Anonymous Monk on Apr 12, 2013 at 16:33 UTC
    Thanks also. I had used Data:Dumper and was confused when I saw 2/8.

      The "2/8" of a hash in scalar context is just a representation of the number of "buckets" used/assigned for the hash. Note that more than one key can be assigned to the same "bucket" depending on how the hashing algorith works on the keys involved and that keys can be redistributed when more "buckets" are assigned as the hash grows.

      $ perl -Mstrict -Mwarnings -E ' > my %hash; > say scalar %hash; > for ( q{a} .. q{z} ) > { > $hash{ $_ } = 1; > say qq{$_ - @{ [ scalar %hash ] }}; > }' 0 a - 1/8 b - 2/8 c - 3/8 d - 4/8 e - 5/8 f - 6/8 g - 6/8 h - 7/16 i - 8/16 j - 9/16 k - 9/16 l - 10/16 m - 10/16 n - 11/16 o - 11/16 p - 14/32 q - 14/32 r - 14/32 s - 15/32 t - 15/32 u - 16/32 v - 16/32 w - 17/32 x - 17/32 y - 18/32 z - 19/32 $

      I hope this is helpful.

      Cheers,

      JohnGG