Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 cooling their heels in the Monastery: (14)
As of 2014-09-19 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (142 votes), past polls