Catman...:lookup(3pm)

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

πŸ’– NAME πŸ’–

Catmandu::Fix::lookup β€” bestie, this is the fix that goes and swaps out the value of a HASH key or an ARRAY index by looking that value up in a dictionary. Like, you give it a value, it checks the dictionary, and boom πŸ’… the value gets replaced. It's giving translator energy.


✨ SYNOPSIS ✨

Okay so first, imagine your dictionary file. It's a little CSV, and honestly? iconic:

# dictionary.csv
# id,planet
# 1,sun
# 2,earth
# 3,moon

Now watch what happens. Any values found in dictionary.csv get replaced:

# values found in the dictionary.csv will be replaced
# {foo => {bar => 2}}
lookup(foo.bar, dictionary.csv)
# {foo => {bar => 'earth'}}

But if the value isn't in the dictionary? No worries, no chaos β€” values not found will be kept, exactly as they were:

# values not found will be kept
# {foo => {bar => 232}}
lookup(foo.bar, dictionary.csv)
# {foo => {bar => 232}}

And if your file uses a different separator, just tell it. Periodt:

# in case you have a different seperator
lookup(foo.bar, dictionary.csv, sep_char: |)

You can also delete the value entirely when the lookup fails:

# delete value if the lookup fails:
lookup(foo.bar, dictionary.csv, delete: 1)

Orrr you can be soft about it and set a fallback. A little default bestie 🫢:

# use a default value if the lookup fails:
lookup(foo.bar, dictionary.csv, default: 'default value')

πŸ‘€ SEE ALSO πŸ‘€

  • Catmandu::Fix
  • Catmandu::Fix::mapping

Okay that's the whole page, bestie! This one's from the User Contributed Perl Documentation, perl v5.40.1, dated 2026-01-24 πŸ’œ Go look up some values, you absolute legend. Mwah! πŸŽ€βœ¨

πŸ“¦ where this page comes from