hblanken has asked for the wisdom of the Perl Monks concerning the following question:

Hello I'm relatively new to this. I have hash of an array and what to add it to a hash name pair.

Stage1
push @ { $LkHigh{$name}}, $value; works!
Stage2
push @( $leakHigh($PartNum}}, {%LkHigh}

when I try to print this I loose the $values in the hash array.

this is what I'm using to print
foreach $PTnum (keys $leakHigh){ foreach $pin (keys %{leakHigh{$PTnum}}){ foreach $i (0 ..$#{leakHigh{$PTnum}{$pin}}){ print "$leakHigh{$PTnum}{$pin}[$i]"; }}}

Replies are listed 'Best First'.
Re: hash of hash of array
by kennethk (Abbot) on Jan 07, 2009 at 22:41 UTC

    First, <code> tags in your posts will help monks interpret your code; see Markup in the Monastery

    There are a number of typos in your posted code. As some of these would prevent the interpreter from running, I will assume some of them are from transcription. You do seem to suffer from some misconceptions regarding structures - please read perlref and perldsc. I have attempted to read your mind and fix the posted code - my frobnitz is on the fritz right now, so I can't guarantee this will do what you want.

    use strict; use warnings; my %LkHigh; my %leakHigh; my @names = ('jim', 'john', 'joe'); my @values = (1, 2, 3); my @PartNums = ('A', 'B', 'C'); # Stage1 for my $i (0 .. $#names) { my $name = $names[$i]; my $value = $values[$i]; push @ { $LkHigh{$name}}, $value; # works! } #Stage2 for my $PartNum (@PartNums) { push @{$leakHigh{$PartNum}}, {%LkHigh}; } # when I try to print this I loose the $values in the hash array. # this is what I'm using to print foreach my $PTnum (keys %leakHigh){ foreach my $pin (0 .. $#{$leakHigh{$PTnum}}){ foreach my $i (keys %{$leakHigh{$PTnum}->[$pin]}){ print "@{$leakHigh{$PTnum}[$pin]{$i}} \n"; } } }