Catman...ashmap(3pm)

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

πŸ’– Catman...ashmap(3pm) πŸ’–

okay bestie, gather round β€” this is a page from the User Contributed Perl Documentation, and it's about a binder that keeps a lil' secret hashmap on the side while your records stream past. It's giving group project energy, except the group project actually slays. 🫢


✨ NAME ✨

Catmandu::Fix::Bind::hashmap β€” a binder to add key/value pairs to an internal hashmap πŸ—‚οΈπŸ’…


🌸 SYNOPSIS 🌸

Bestie, here's the vibe. Finding non-unique ISBN numbers in the record stream? Say less:

# Find non unique ISBN numbers in the record stream
do hashmap(join: ',')
   copy_field(isbn,key)
   copy_field(_id,value)
end

And then it just... exports a whole hash map to the JSON exporter, containing every isbn occurrence in the stream. Iconic behaviour, no cap:

# will export to the JSON exporter a hash map containing all isbn occurrences in the stream

{ "_id": "9781565920422" , "value": "rec0001,rec0329,rec1032" }
{ "_id": "9780596004927" , "value": "rec0718" }

Now β€” what if you literally do not care about the values and just wanna count how many times each ISBN shows up? Also valid, also slay:

# Ignore the values. Count the number of ISBN occurrences in a stream
# File: count.fix:
do hashmap(count: 1)
   copy_field(isbn,key)
end

And then you use the Null exporter to suppress the normal output, because we are ✨above✨ normal output:

# Use the Null exporter to suppress the normal output
$ cat /tmp/data.json | catmandu convert JSON --fix count.fix to Null

πŸ¦‹ DESCRIPTION πŸ¦‹

The hashmap binder will insert all key/value pairs given to a internal hashmap that can be exported using an Catmandu::Exporter. (yes bestie, it just hoards them in there for you πŸ’œ)

The 'key' fields in the internal hashmap will be exported as '_id' field. So like, the key gets a glow-up and a new name. πŸ’…

If the key in the hashmap Bind is an ARRAY, then multiple key/value pairs will be inserted into the hashmap. multiple!! at once!! πŸŽ€

By default all the values will be added as an array to the hashmap. Every key will have one or more values. Use the 'join' parameter to create a string out of this array. 🧚


πŸ‘‘ CONFIGURATION πŸ‘‘

πŸ“ exporter: EXPORTER

The name of an exporter to send the results to. Default: JSON. Extra parameters can be added:

do hashmap(exporter: JSON, file:/tmp/data.json, count: 1)
  ...
end

🌈 store: STORE

Send the output to a store instead of an exporter. Extra parameters can be added:

do hashmap(store: MongoDB, database_name: test, bag: data, count: 1)
  ...
end

⭐ uniq: 0|1

When set to 1, then all values in the key 'value' will be made unique. dedupe era ✨

πŸŽ€ join: CHAR

Join all the values of a key using a delimiter. Pick your separator, bestie, and let it cook. πŸ”₯

πŸ’€ count: 0|1

Don't store the values β€” only count the number of key occurrences. minimalist queen behaviour, honestly πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯

  • Catmandu::Fix::Bind

k that's the whole thing, you ate it, you understood it, mwah πŸ’–

This little masterpiece comes to you courtesy of perl v5.40.1, dated 2026-01-24 β€” so go forth, bind your hashmaps, and remember: the values were inside you all along πŸ¦‹βœ¨πŸ’…

πŸ“¦ where this page comes from