Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: alphabetize a hash ignoring upper/lower cases

by tstock (Curate)
on May 11, 2003 at 07:48 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found