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

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;


Comment on Re: alphabetize a hash ignoring upper/lower cases
Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (19)
As of 2015-07-29 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls