sort(3perl)

✨ sort β€” the perl pragma that used to control how sort() behaves ✨

okay bestie, gather round, because this one is a whole journey and honestly it's giving "retired icon living her best quiet life". This page is sort, from the Perl Programmers Reference Guide, and by the end you're gonna understand exactly why it does basically nothing now. πŸŽ€


🌸 SYNOPSIS

so here's the tea: the sort pragma is now a no-op, and using it is actively discouraged. These three operations are valid and will not error out, but they also do literally nothing:

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

yep. three whole incantations, zero effect. it's giving ritual. it's giving ✨aesthetic✨. it's giving use sort 'stable'; as a vibe, not a feature. πŸ’…


πŸ’– DESCRIPTION

so, historically β€” meaning back in the day β€” the sort pragma was how you'd control the behaviour of the builtin sort() function. like, you could actually tell Perl what kind of sort you wanted. main character pragma era. πŸ‘‘

Prior to v5.28.0 there were two other options too:

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

and if you try to specify either of those in v5.28 or later? it will croak. πŸ’€ no mercy, no warning, just death. bestie do not test this in prod.

okay now the big glow-up: the default sort has been stable since v5.8.0. that's almost two decades of consistent behaviour, and because of that everyone has just... come to assume stability. which is fair, honestly. it's been stable longer than some of us have been alive. 😭

and stability will remain the default. that's the whole point β€” there's no need for a pragma so your code can opt into stability "just in case" things change, because it won't. periodt. 🫢

the maintainers also do not foresee going back to offering multiple implementations of general purpose sorting β€” so there's no future need for a pragma to choose between them either. that door is closed, painted, and honestly it looks great.

now, 🌈 if you know you care that much about the performance of your sorting, and you know that for your use case and your data it was actually worth investigating alternatives, and you were able to identify an alternative from the default that was genuinely better, and the cost of switching was worth it β€” then friend, you know more than they do. (iconic of you, honestly.) and likely, whatever choices they could give you are not as good as just implementing your own. for example: a Radix sort can be faster than O(n log n), but it can't be used for all keys and it has larger overheads. so like, tradeoffs are real. πŸ¦‹

and finally: they are not averse to changing the sort algorithm! they just don't see the benefit in offering you the choice of two general purpose implementations. one algorithm, one destiny, no drama. 🧚


⚠️ CAVEATS

okay this part is the sad one, brace yourself. 😭

the function sort::current() was provided to report the current state of the sort pragmata. two things about it:

  • it was not exported
  • and there is no code to call it on CPAN

so it's basically a legend nobody ever actually summoned. it's now deprecated, and it will warn by default β€” so if you go poking at it, expect Perl to be like "bestie. no."

and here's why: since they no longer store any sort "state" at all, it can no longer return the correct value. so it will always return the string "stable" β€” which, to be fair, is consistent with what they actually have implemented. πŸ’œ at least it's honest about it. no cap.

🚨 lowkey important: don't build anything on sort::current(). it's deprecated, it warns, and it's permanently "stable" now. there's no state to read because there's no state left to read. πŸ’€

🌟 SEE ALSO

hmm, nothing extra listed here β€” but honestly the whole point of this page is that there's not much left to see. the pragma is a no-op, the state is gone, the icon has retired. slay though. πŸ‘‘


and that's the whole page, bestie! this was sort(3perl) from the Perl Programmers Reference Guide, perl v5.44.0, dated 2026-10-17. πŸŽ€βœ¨ go forth and just... use sort() like a normal person, it's stable, it's always been stable, it will stay stable. mwah. πŸ’…πŸ’–

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms