Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Answer: How do I sort a list in reverse order?

( #2257=categorized answer: print w/ replies, xml ) Need Help??

Q&A > sorting > How do I sort a list in reverse order? contributed by vroom

Use a sort block and switch the positions of the special variable $a and $b
@sorted=sort{$b cmp $a} @unsorted; # for strings @sorted=sort($b <=> $a) @sorted; # for number
Another option is:
@sorted=reverse sort @unsorted #for strings

Comment on Answer: How do I sort a list in reverse order?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (20)
As of 2014-10-02 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (61 votes), past polls