Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: how to put hash key and value in order

by LanX (Bishop)
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009674]
help
Chatterbox?
[erix]: just FYI, that link also mentioned the interesting word Hellweg
[erix]: but that's probably a known word to you guys

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2017-12-12 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (335 votes). Check out past polls.

    Notices?