Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials
( categories: )

By default the sort function uses alphabetical order to sort elements. To sort using numerical order, you have to use the syntax shown below.

- In ascending order:

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

- In descending order:

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