How to sort an array in perl

Sorting an array is an important function and some or most of the languages provide an in-built function to perform this operation. Perl provides this in-built functionality, by means of “sort” function. Using sort function an array in perl can be sorted in both ascending and descending order. Now, let’s say the given array @array and is initialized as follows:

Below are the various ways to sort the given array numerically in ascending, descending and ascii order.

Sorting an array in ascending order

Output would be:
2 3 4 6 11

Sorting an array in descending order

Output would be:
11 6 4 3 2

Sorting an array in ASCII order

Output would be:
11 2 3 4 6

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">