sort(3pm)

πŸ’… sort(3pm) β€” the perl pragma that used to control how sort() behaves (key word: used to)

okay bestie so this is a page from the Perl Programmers Reference Guide, and honestly? It's giving retirement announcement. The sort pragma is out here living its best no-op life, and we're all just gonna have to accept it. 🫢


✨ NAME ✨

sort β€” a perl pragma whose whole job was to control sort() behaviour, and which now does, um, nothing. Iconic of it honestly. πŸ’…


🌸 SYNOPSIS 🌸

The sort pragma is now a no-op, and its use is discouraged (yes, the docs are side-eyeing you). These three operations are still valid, but like... they have no effect:

use sort 'stable';          # guarantee stability
use sort 'defaults';        # revert to default behavior
no  sort 'stable';          # stability not important

You can write them. They'll parse. Nothing will happen. It's giving "sending a text into the void" energy. πŸ’€


πŸ¦‹ DESCRIPTION πŸ¦‹

So historically β€” like, back in the day β€” the "sort" pragma let you control the behaviour of the builtin sort() function. That was its whole personality.

Prior to v5.28.0 there were two other options:

use sort '_mergesort';
use sort '_qsort';          # or '_quicksort'

If you try and specify either of these in v5.28+, it will croak. πŸ”₯ Not a vibe check, an actual croak. Don't test it unless you enjoy that.

The default sort has been stable since v5.8.0, and given this consistent behaviour for almost two decades, everyone has come to assume stability. Which, fair. Two decades is a long situationship.

Stability will remain the default β€” hence there is no need for a pragma for code to opt into stability "just in case" this changes β€” it won't. Periodt. ✨

We do not foresee going back to offering multiple implementations of general purpose sorting β€” hence there is no future need to offer a pragma to choose between them. The pragma pipeline is dry, babes.

Okay but like, if you know that you care that much about performance of your sorting, and that for your use case and your data, it was worth investigating alternatives, possible to identify an alternative from our default that was better, and the cost of switching was worth it β€” then you know more than we do, and honestly? Slay. πŸ‘‘ Likely whatever choices we can give are not as good as implementing your own. (For example, a Radix sort can be faster than O(n log n), but can't be used for all keys and has larger overheads.) Look at you, main character of algorithm selection. 🧚

We are not averse to changing the sort algorithm, but we don't see the benefit in offering the choice of two general purpose implementations. One sort to rule them all, etc etc. πŸ’–


πŸŽ€ CAVEATS πŸŽ€

The function sort::current() was provided to report the current state of the sort pragmata. Two things about it, bestie:

  • This function was not exported.
  • There is no code to call it on CPAN.

It is now deprecated, and will warn by default. 😭 So if you're out here calling it, expect the perl interpreter to gently yell at you.

And since we no longer store any sort "state", it can no longer return the correct value, so it will always return the string "stable" β€” as this is consistent with what we actually have implemented. Not a bug, a lifestyle. πŸ™ˆ

fr fr, don't build anything on top of sort::current(). It's cosplaying as a real function at this point. πŸ’€

🌈 a lil sign-off 🌈

This glamorous little page comes to you from perl v5.42.3, dated 2026-11-03, and it's filed under sort(3pm) in case you need to find it again. Go forth and sort things β€” the default will be stable, and so will you. πŸ’œπŸ“πŸŽ€

πŸ“¦ where this page comes from