This solution is similar to
tim's but doesn't use a second intermediate data structure. It uses the flattened hash (from the first step) inline.
# selected stores
my @st= ('STORE2','STORE3','STORE5');
# list of stores (doesn't keep duplicates)
my %stores= map { %$_ } values %bighash;
+
foreach my $store ( sort { $stores{$b}[0] <=> $stores{$a}[0] } @st ) {
my $products= $stores{$store};
my $earned = shift @$products;
+
print "STORE: $store EARNING: $earned\n";
foreach my $product ( @$products ) {
print join( "," => @$product ), "\n";
}
print "\n";
}
As
tim says, without a more detailed problem description, it seems that the extra level of nesting in
%bighash (set1, set2, etc.) is unnecessary.