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

Fellow monks,
I have run into a little jam and need your wisdom
I have a hash which looks as follows:
$somehash{a1}{justtest}{value1}=1 $somehash{a1}{justtest}{value2}=2 $somehash{a1}{justtest}{value3}=3 $somehash{a2}{justtest}{value1}=1 $somehash{a2}{justtest}{value2}=2 $somehash{a2}{justtest}{value3}=3 . . .
Now I have a problem sorting through the hash especially to loop through 'value1,value2,value3'
My desired output after looping through the hash would be:
a1:1 a1:2 a1:3 a2:1 a2:2 a2:3
My current code for the hash is:
foreach $key1 (sort keys %somehash) { # here is where I don't know how to loop through all the 'value1,val +ue2,value3'.Consider those would not necessarily be name the same way +. }
Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Hash question
by ikegami (Patriarch) on Aug 04, 2005 at 17:19 UTC
    foreach my $key1 (sort keys %somehash) { foreach my $key2 (sort keys %{$somehash{$key1}}) { foreach my $key3 (sort keys %{$somehash{$key1}{$key2}}) { print($key1, ':', $somehash{$key1}{$key2}{$key3}, "\n"); } } }
    or
    foreach my $key1 (sort keys %somehash) { my $key2 = 'justtest'; foreach my $key3 (sort keys %{$somehash{$key1}{$key2}}) { print($key1, ':', $somehash{$key1}{$key2}{$key3}, "\n"); } }
    or
    foreach my $key1 (sort keys %somehash) { foreach my $key2 (sort keys %{$somehash{$key1}{justtest}}) { print($key1, ':', $somehash{$key1}{justtest}{$key2}, "\n"); } }
Re: Hash question
by cool_jr256 (Acolyte) on Aug 04, 2005 at 17:26 UTC
    Thanks alot. Exactly what I was missing.
    Thanks again.