Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Sorting by Hash Slice

by sacked (Hermit)
on Jul 28, 2005 at 04:57 UTC ( [id://478824]=note: print w/replies, xml ) Need Help??


in reply to Sorting by Hash Slice

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.

--sacked

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://478824]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found