in reply to Re: hash of hashes and memory space...
in thread hash of hashes and memory space...

My question came about from looking at the output of a Data::Dumper and Data::Dump of a hash of hashes I am working with. Dumping the hash only prints the first hash key/value pairs not the under lining hashes or their key/value pairs. This made me think that a hash of hashes is not one single variable (container) but that each embedded hash is it's own separate container.
  • Comment on Re^2: hash of hashes and memory space...

Replies are listed 'Best First'.
Re^3: hash of hashes and memory space...
by ikegami (Patriarch) on Mar 23, 2010 at 20:16 UTC
    A "hash of hash" is really a "hash of references to hashes".
    $h{foo}{bar} = 123;
    is short for
    $h{foo}->{bar} = 123;
    and
    ${ $h{foo} }{bar} = 123;

    Something to try:

    my %a; my %b; $a{foo} = \%b; $a{foo}{bar} = 123; print("$b{bar}\n");
Re^3: hash of hashes and memory space...
by jethro (Monsignor) on Mar 24, 2010 at 01:33 UTC

    Strange. When I use Data::Dumper, I get all the subhashes shown too. Example:

    #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my %hash= ( 4, {3,4,5,6,7,8}); $hash{a}{b}{c}{d}{e}=366; print Dumper(\%hash); #output: $VAR1 = { '4' => { '3' => 4, '7' => 8, '5' => 6 }, 'a' => { 'b' => { 'c' => { 'd' => { 'e' => 366 } } } } };

    Maybe $Data::Dumper::Maxdepth is set to 1 in your script

      print Dumper(\%hash);

      You found my problem with Data::Dumper...

      I was using print Dumper(%hash);

      Thanks!