3dbc has asked for the wisdom of the Perl Monks concerning the following question:
Consistent with the above example I would like to use $array1 as a hash key but inside of a more complex Hash of Hashes which would associate $array3, $array4, $array5 ... using the array name as the subkey for the nested hash.my %myhash = map { $array1[$_] => $array2[$_] } 0 .. $#array1;
etc. etc. until all the arrays have been associated within the HoH.my %HoH = map { $array1[$_] => “array2” => $array2[$_] } 0 .. $#array1 +; %HoH = map { $array1[$_] => “array3” => $array3[$_] } 0 .. $#array1; %HoH = map { $array1[$_] => “array4” => $array4[$_] } 0 .. $#array1; %HoH = map { $array1[$_] => “array5” => $array5[$_] } 0 .. $#array1;
Is the above code a proficient way of associating all arrays with the array1 keys within the same data structure?Foreach @array1 { print $HoH{$array1[$_]}{array5} # array5 associated with array1 print $HoH{$array1[$_]}{array4} # array4 associated with array1 print $HoH{$array1[$_]}{array3} # array3 associated with array1 # etc. etc. }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: converting arrays to a complex HoH data structure
by Enlil (Parson) on Jan 06, 2004 at 21:25 UTC | |
|
Re: converting arrays to a complex HoH data structure
by kesterkester (Hermit) on Jan 06, 2004 at 21:19 UTC |