Perl sort Function

Advertisements


Description

This function sorts LIST according to the subroutine SUBNAME or the anonymous subroutine specified by BLOCK. If no SUBNAME or BLOCK is specified, then it sorts according to normal alphabetical sequence.

If BLOCK or SUBNAME is specified, then the subroutine should return an integer less than, greater than, or equal to zero, according to how the elements of the array are to be sorted

Syntax

Following is the simple syntax for this function:

sort SUBNAME LIST

sort BLOCK LIST

sort LIST

Return Value

This function returns sorted list.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl -w

@array = ("z", "w", "r", "i", "b", "a");
print("sort() ", sort(@array), "\n");

When above code is executed, it produced following result

sort() abirwz


Advertisements
Advertisements