###  > Hi, Just trying to understand hash of hash of array.
###  > my %LIS; my $pet='dog';my $x='fido'; my $y=5; my $z='male';
###  > $LIS{$pet}{$x} = [$y,$z];
###  > print "@{$LIS{$pet}{$x}}"; # ok, prints '5 male'
###  > Now, suppose %LIS is populated with lots of pets.
###  > How to get a list of the $z sorted on $y for the dogs ?
###  > my @LIS = sort { ????? }@{$LIS{'dog'}{$x}}; ???
###  > Thanks
###
###  Better invest a bit more in meaningful names and in more data:
###  (I haved improved the formating a bit)


my %LIS; 

for ( "dog  Fido  5 male   ",
      "dog  Woffo 8 male   ",
      "cat  Maunz 2 female ",
      "bird Pieps 1 male   "   )     {
  ($pet, $name, $age, $gender) = split;
  $LIS{$pet}{$name} = [$age,$gender];    }

print "- - - - my HoHoL: - - - -\n";
for $keysPet(keys %LIS)     {
  print $keysPet, "\n";
  for $keysName( keys %{$LIS{$keysPet}} )   {
    printf "           %-6s %2s   %-12s \n",
                   $keysName, $LIS{$keysPet}{$keysName}[0], 
                              $LIS{$keysPet}{$keysName}[1];
    push @lis, $LIS{$keysPet}{$keysName}[0],  ### (1) 
      sprintf "\n%-6s  %-6s %2s   %-12s  ",   ### (2) 
         $keysPet, $keysName, $LIS{$keysPet}{$keysName}[0], 
                              $LIS{$keysPet}{$keysName}[1];  }  }
%lis = @lis;                                  ### (3)
print "\n\n- - - - by age: - - - -\n";
for (sort(keys %lis)) {                       ### (4)
   print $lis{$_}   }


###  According to my present opinion I can only sort lists 
###  but not a wide branched, feathered, hairy hashes landscape; 
###  so I have to push my sort item (1) and my data (2) into an 
###  appropriate list (1),
###  copy that list to a hash (3) and print them after sorting (4).
###  
###  Regards, Detlef Lindenthal

Reply via email to