Catman...ashmap(3pm)
π 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
- 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