in reply to Help with Hash of hashes, is there a better way?
my @targets; while(my($env,$platform_href) = each %{$stuff}) { while(my($platform,$host_href) = each %{$platform_href}) { while(my($host,$target_href) = each %{$host_href}) { while(my($target,$capacity_href) = each %{$target_href}) { push @targets, { env => $env, platform => $platform, host => $host, target => $target, total_capacity => $capacity_href->{'total_capacity'} +, free_capacity => $capacity_href->{'free_capacity'}, }; } } } } # now, whereever you previously had the 4 nested loops, just do: foreach my $target ( @targets ){ # Do stuff with these keys of %$target: # env # platform # host # target # total_capacity # free_capacity }
|
|---|