Catman...t_field(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– 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:

  1. undef_position: last β€” pushes undefined values to the end of the list. This is the default. πŸ’–
  2. undef_position: first β€” pushes undefined values to the beginning of the list. ⭐
  3. undef_position: delete β€” removes undefined values from the list entirely. bye felicia πŸ‘‹
⚠️ beware, fr fr: reverse has no effect on undef_position: last and it has no effect on undef_position: first either. The original says it twice, so we're saying it twice. Do not come for me when your reverse: 1 doesn'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