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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.