Catman...:index(3pm)

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

✨ NAME ✨

okay so bestie, welcome to Catman...:index(3pm) πŸ’– β€” this is a page from the User Contributed Perl Documentation crew, and it's giving absolute baddie energy. It's the manual for Catmandu::Fix::index β€” the fix that goes and finds every single position of a (sub)string inside a field. like a little treasure hunt but for characters. πŸ”βœ¨


🌸 SYNOPSIS 🌸

so here's the whole vibe, no cap. first up, strings β€” you're hunting for where a character shows up inside a string:

# On strings, search the occurence of a character in a string

# word => "abcde"
index(word,'c')                   # word => 2
index(word,'x')                   # word => -1

okay so 'c' lives at index 2, iconic. and 'x'? not there at all bestie, so you get -1 😭 (that's the universal "nope, didn't find it" signal, periodt).

now the multiple era β€” when you want every position and not just the first one:

# word => "abccde"
index(word,'c', multiple:1)       # word => [2,3]

look at that, [2,3] β€” two 'c's, two positions, both of them slaying. πŸ’…

and then we get into the '*' magic, where you loop over all the word(s):

# word => [a,b,bba] , loop over all word(s) with the '*'
index(word.*,'a')                 # word -> [0,-1,2]

0, -1, 2 β€” the -1 is just b being unbothered and having zero as, we respect it. πŸ™ˆ

last but never least: arrays, where you're searching for the occurrence of a word in an array instead:

# words => ["foo","bar","foo"]
index(words,'bar')                # words => 1
index(words,'foo', multiple: 1)   # words => [0,2]

'bar' shows up at 1, and both the 'foo's come through at [0,2] β€” main character energy from the array, honestly. πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

  • Catmandu::Fix β€” go read it bestie, it's the whole family tree and you'll need the lore. πŸ’œ

and that's the page, angel! πŸŽ€ this masterpiece was living in perl v5.40.1 and it dropped on 2026-01-24 β€” so if you ever need to cite your sources, you know exactly where it came from. go forth and index everything, iykyk ✨🫢

πŸ“¦ where this page comes from