and returns the sorted
list value. By default (without a
it sorts in standard string comparison order (undefined
values sorting before defined null strings, which sort before everything else).
, if given, may be the name of a subroutine or a code block
(anonymous subroutine) that defines its own comparison mechanism for sorting
. 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
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
are passed by reference,
so don't modify them in the
Do not declare
). They are package
globals (though theyre exempt from the usual restrictions on globals when
). You do need to make sure your
routine is in the same package though, or else you must qualify
with the package name of the caller.
In versions preceding 5.005,
implemented in terms of C's
versions will dump core if your
sort subroutine provides inconsistent ordering of values.
As of 5.005, however, this is no longer true.