As promised, here's some skeleton code (and sample data) to get you started:
#!/usr/bin/perl use strict; use warnings; use feature qw/say/; my %data_hash = ( "key0.1" => [ { "key1.1" => 3.3, "key1.2" => 17.8, "key1.3" => -2.4, }, { "key1.4" => 5.1, "key1.5" => 13, }, { "key1.6" => -69, "key1.7" => 127, "key1.8" => 2.718, "key1.9" => 3.3, }, ], "key0.2" => [ { "key1.10" => 3.3, "key1.11" => 2.5, }, { "key1.12" => -33, }, ], ); my %flat_hash = (); foreach my $key0 (keys %data_hash) { foreach my $index (0 .. $#{$data_hash{$key0}}) { foreach my $key1 (keys %{$data_hash{$key0}->[$index]}) { my $new_key = "$key0-$index-$key1"; $flat_hash{$new_key} = { "value" => $data_hash{$key0}->[$index]->{$key1}, "key0" => $key0, "index" => $index, "key1" => $key1, }; } } } foreach (sort { $flat_hash{$a}->{"value"} <=> $flat_hash{$b}->{"value" +} } keys %flat_hash) { say $flat_hash{$_}->{"value"}, ": key0 = ", $flat_hash{$_}->{"key0"}, ", index = ", $flat_hash{$_}->{"index"}, ", key1 = ", $flat_hash{$_}->{"key1"}; }
I didn't integrate the %limit_hash part since it wasn't part of your question.
N.B. - you can probably do this more easily and naturally still using map, but I just came back from an Apple Family reunion and am not yet thinking in Perl again. ;)
In reply to Re^2: sorting hash of array of hashes by value
by AppleFritter
in thread sorting hash of array of hashes by value
by Special_K
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |