sort [code] list
Sorts a list and returns the sorted
list value. By default (without a code argument),
it sorts in standard string comparison order (undefined
values sorting before defined null strings, which sort before everything else).
code, if given, may be the name of a subroutine or a code block
(anonymous subroutine) that defines its own comparison mechanism for sorting
elements of list. The routine must return to the
an integer less than, equal to, or greater than 0, depending on how the
elements of the list are to be ordered. (The handy
cmp operators can be used to perform three-way numeric
and string comparisons.)
The normal calling
code for subroutines is bypassed, with the following effects: the subroutine may
not be a recursive subroutine, and the two elements to be compared are passed
into the subroutine as
$b are passed by reference,
so don't modify them in the
Do not declare
$b as lexical
my). They are package
globals (though theyre exempt from the usual restrictions on globals when
use strict). You do need to make sure your
routine is in the same package though, or else you must qualify
$b with the package name of the caller.
In versions preceding 5.005,
implemented in terms of C's
qsort(3) versions will dump core if your
sort subroutine provides inconsistent ordering of values.
As of 5.005, however, this is no longer true.