Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL sort Function



Syntax

sort SUBNAME LIST

sort BLOCK LIST

sort LIST


Definition and Usage

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.

Return Value

  • Returns sorted list

Example

Try out following example:

#!/usr/bin/perl -w

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

It will produce following result:

sort() abirwz


Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names