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

Re: alphabetize a hash ignoring upper/lower cases

by tstock (Curate)
on May 11, 2003 at 07:48 UTC ( #257200=note: print w/replies, xml ) Need Help??

in reply to alphabetize a hash ignoring upper/lower cases

vladb answer works fine, and I would like to add that if the code you posted is actually what you are doing instead of a simplified example, then you really don't need the keys of the hash and it can all be written as:
my @mips = sort { lc($a) cmp lc($b) } values %mips;

Replies are listed 'Best First'.
Re: Re: alphabetize a hash ignoring upper/lower cases
by Anonymous Monk on May 11, 2003 at 11:59 UTC
    if you have a lot of elements doing the case conversion everytime you compare two elements this will be inefficent. i'd suggest:
    my @imps = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { [ lc $_, $_ ] } values %mips;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://257200]
and the leaves swirl about...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-06-22 00:44 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.