Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Sorting - lower to upper

by ccn (Vicar)
on Jul 15, 2004 at 15:54 UTC ( [id://374699]=note: print w/replies, xml ) Need Help??


in reply to Sorting - lower to upper

You can not have a sorted hash, but you can sort it's keys before use

foreach ( sort { ord($a) <=> ord($b) } keys %hash ) { print "$_ => $hash{$_}\n" }

Replies are listed 'Best First'.
Re^2: Sorting - lower to upper
by shemp (Deacon) on Jul 15, 2004 at 16:32 UTC
    Your comparison is backwards, the OP wants the lowercase first so you need:
    foreach ( sort { ord($b) <=> ord($a) } keys %hash ) { print "$_ => $hash{$_}\n" }
    Kudos though, much more elegant than the solution i posted!
Re^2: Sorting - lower to upper
by joule (Acolyte) on Jul 15, 2004 at 17:07 UTC
    This works after switching the $a and $b.

    Thank you all for your kind help.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found