Sorts the
LIST and returns the sorted list value. If
SUBNAME or
BLOCK is omitted, sorts in standard string comparison order. If
SUBNAME is specified, it gives the name of a subroutine that returns an integer less than, equal to, or greater than 0, depending on how the elements of the array are to be ordered. (The
<=> and cmp
operators are extremely useful in such routines.)
SUBNAME may be a scalar variable name, in which case the value provides the name of the subroutine to use. In place of a
SUBNAME, you can provide a
BLOCK as an anonymous, in-line sort subroutine.

In the interests of efficiency 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 not via @_ but as the package global variables $a and $b (see example below). They are
passed by reference, so don't modify $a and $b. And
don't try to declare them as lexicals either.

You also cannot exit out of the sort block or subroutine using any of the
loop control operators described in the perlsyn manpage or with goto().

When use locale is in effect, sort LIST sorts
LIST according to the current collation locale. See the perllocale manpage.

If you're using strict, you MUST NOT declare $a and $b as lexicals. They are
package globals. That means if you're in the main package, it's

@articles = sort {$main::b <=> $main::a} @files;

or just

@articles = sort {$::b <=> $::a} @files;

but if you're in the FooPack package, it's

@articles = sort {$FooPack::b <=> $FooPack::a} @files;

The comparison function is required to behave. If it returns inconsistent
results (sometimes saying $x[1] is less than $x[2] and sometimes saying the
opposite, for example) the Perl interpreter will probably crash and dump
core. This is entirely due to and dependent upon your system's
qsort(3) library routine; this routine often avoids sanity
checks in the interest of speed.