1sort(3pm)              Perl Programmers Reference Guide              sort(3pm)
2
3
4

NAME

6       sort - perl pragma to control sort() behaviour
7

SYNOPSIS

9       The sort pragma is now a no-op, and its use is discouraged. These three
10       operations are valid, but have no effect:
11
12           use sort 'stable';          # guarantee stability
13           use sort 'defaults';        # revert to default behavior
14           no  sort 'stable';          # stability not important
15

DESCRIPTION

17       Historically the "sort" pragma you can control the behaviour of the
18       builtin "sort()" function.
19
20       Prior to v5.28.0 there were two other options:
21
22           use sort '_mergesort';
23           use sort '_qsort';          # or '_quicksort'
24
25       If you try and specify either of these in v5.28+ it will croak.
26
27       The default sort has been stable since v5.8.0, and given this
28       consistent behaviour for almost two decades, everyone has come to
29       assume stability.
30
31       Stability will remain the default - hence there is no need for a pragma
32       for code to opt into stability "just in case" this changes - it won't.
33
34       We do not foresee going back to offering multiple implementations of
35       general purpose sorting - hence there is no future need to offer a
36       pragma to choose between them.
37
38       If you know that you care that much about performance of your sorting,
39       and that for your use case and your data, it was worth investigating
40       alternatives, possible to identify an alternative from our default that
41       was better, and the cost of switching was worth it, then you know more
42       than we do. Likely whatever choices we can give are not as good as
43       implementing your own. (For example, a Radix sort can be faster than
44       O(n log n), but can't be used for all keys and has larger overheads.)
45
46       We are not averse to changing the sort algorithm, but we don't see the
47       benefit in offering the choice of two general purpose implementations.
48

CAVEATS

50       The function "sort::current()" was provided to report the current state
51       of the sort pragmata. This function was not exported, and there is no
52       code to call it on CPAN. It is now deprecated, and will warn by
53       default.
54
55       As we no longer store any sort "state", it can no longer return the
56       correct value, so it will always return the string "stable", as this is
57       consistent with what we actually have implemented.
58
59
60
61perl v5.36.0                      2022-08-30                         sort(3pm)
Impressum