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.