Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Answer: How do I do a natural sort on an array?

by indigo (Scribe)
on Mar 30, 2001 at 00:53 UTC ( #68189=categorized answer: print w/replies, xml ) Need Help??

Q&A > sorting > How do I do a natural sort on an array? - Answer contributed by indigo

@a = sort @b;

will sort lexigraphically.

@a = sort { $a <=> $b } @b;

will sort numerically.

@a = sort &naturally @b;

will sort "naturally", where naturally() is a compare routine of your own devising.

perldoc -f sort for more info.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2016-10-01 19:56 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (7 votes). Check out past polls.