Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: how to put hash key and value in order

by LanX (Canon)
on Dec 20, 2012 at 02:52 UTC ( #1009674=note: print w/ replies, xml ) Need Help??


in reply to how to put hash key and value in order

supposing that coin values are unique:

DB<106> %coins = ( "Quarter" , 25, "Dime" , 10, "Nickel", 5 ); => ("Quarter", 25, "Dime", 10, "Nickel", 5) DB<107> %cents= reverse %coins => (25, "Quarter", 10, "Dime", 5, "Nickel") DB<108> for $cent (sort {$a<=>$b} keys %cents) { print "$cents{$cent},$cent\n" } Nickel,5 Dime,10 Quarter,25

Cheers Rolf


Comment on Re: how to put hash key and value in order
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-07-30 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls