Perl Programming/Keywords/sort

Previous: socketpair Keywords Next: splice

The sort keyword edit

sort sorts the LIST alphabetically and returns the sorted list value when called from list context. The behaviour is undefined for a call from scalar context.

Without BLOCK or SUBNAME, the sort is done in standard string comparison order. SUBNAME is the name of a subroutine that returns an integer less than, equal to, or greater than zero depending on the ordering of the elements in the list. SUBNAME can also be a scalar variable name where its value provides the name of or a reference to the subroutine. Instead of an existing subroutine, the BLOCK can contain the code as an in-line subroutine without a name.

Syntax edit

  sort SUBNAME LIST
  sort BLOCK LIST
  sort LIST

See also edit

Previous: socketpair Keywords Next: splice