Catman...t_field(3pm)
π NAME π
Catmandu::Fix::sort_field β bestie, it literally sorts the values of an array. That's the whole gig. And it ate. π
This is part of the User Contributed Perl Documentation collection, so you already know it's giving β¨community-crafted, beloved-by-the-peopleβ¨ energy.
β¨ SYNOPSIS β¨
okay so here's the vibe β you hand it an array, it hands you back order. no cap. π¦
# e.g. tags => ["foo", "bar","bar"]
sort_field(tags) # tags => ["bar","bar","foo"]
sort_field(tags, uniq: 1) # tags => ["bar","foo"]
sort_field(tags, uniq: 1, reverse: 1) # tags => ["foo","bar"]
# e.g. nums => [ 100, 1 , 10]
sort_field(nums, numeric: 1) # nums => [ 1, 10, 100]
#push undefined values to the end of the list (default)
#beware: reverse has no effect on this!
sort_field(tags,undef_position: last)
#push undefined values to the beginning of the list
#beware: reverse has no effect on this!
sort_field(tags,undef_position: first)
#remove undefined values from the list
sort_field(tags,undef_position: delete)
Look at sort_field(tags) just... alphabetizing your chaos. ["foo", "bar","bar"] walks in a mess and leaves as ["bar","bar","foo"]. iconic behavior honestly. π
Then sort_field(tags, uniq: 1) says "and let's not do duplicates today bestie" β ["bar","foo"]. πΈ
And sort_field(tags, uniq: 1, reverse: 1)? now it's ["foo","bar"] β flipping the whole thing around like a main character hair toss. πββοΈ
Now for the numbers, because NUMBERS DO NOT SORT LIKE STRINGS, and this is the part that gets everybody π:
# e.g. nums => [ 100, 1 , 10]
sort_field(nums, numeric: 1) # nums => [ 1, 10, 100]
numeric: 1 is your girl here β [ 100, 1 , 10] becomes [ 1, 10, 100] instead of whatever cursed lexicographic situation would've happened. π₯
π«§ undefined values, a whole saga π«§
You got three moves, bestie, pick your fighter:
undef_position: lastβ pushes undefined values to the end of the list. This is the default. πundef_position: firstβ pushes undefined values to the beginning of the list. βundef_position: deleteβ removes undefined values from the list entirely. bye felicia π
β οΈ beware, fr fr:reversehas no effect onundef_position: lastand it has no effect onundef_position: firsteither. The original says it twice, so we're saying it twice. Do not come for me when yourreverse: 1doesn't move the undefs. It's not supposed to. π
π SEE ALSO π
Catmandu::Fixβ the mothership. go say hi. π«Ά
written for perl v5.40.1, dated 2026-01-24 β mwah, xoxo, go sort something pretty ππβ¨
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR 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