Tie::SubstrHash(3pm)
β¨ NAME β¨
Okay so bestie, welcome to Tie::SubstrHash β the Perl module that does fixed-table-size, fixed-key-length hashing. That's the whole vibe. It's a hash. But make it rigid. π
This page lives in the Perl Programmers Reference Guide and honestly? It's a little gem.
πΈ SYNOPSIS πΈ
require Tie::SubstrHash;
tie %myhash, 'Tie::SubstrHash', $key_len, $value_len, $table_size;
That's it. Three little numbers and you're tied. π
π DESCRIPTION π
So the Tie::SubstrHash package gives you a hash-table-like interface to an array of determinate size β with a constant key size and a constant record size. It's giving structured. It's giving locked-in. It's giving no surprises.
When you tie a new hash to this package, you (the developer, the main character) have to specify three things:
- the size of the keys that will be used,
- the size of the value fields that the keys will index,
- and the size of the overall table β and that's in terms of key-value pairs, not size in hard memory, iykyk.
These values will not change for the duration of the tied hash. Periodt. Once it's set, it's set.
Your newly-allocated hash table can now have data stored and retrieved. Slay. π«Ά But listen β there are rules, and they are strict:
Store more than$table_sizeelements? Fatal error. π Store a value that isn't exactly$value_lencharacters long? Fatal error. π Reference through a key that isn't exactly$key_lencharacters long? Fatal error. π₯
Like yes, these constraints may seem excessive β lowkey they are β but the result is a hash table that uses much less internal memory than an equivalent freely-allocated hash table. So likeβ¦ it's a trade-off bestie. Rigidity in exchange for efficiency. Iconic behaviour honestly. π
π¦ CAVEATS π¦
Now for the fine print, and you know we have to talk about it:
- Because the current implementation uses the table and key sizes for the hashing algorithm, there is no means by which to dynamically change the value of any of the initialization parameters. So don't even try to glow-up those numbers mid-flight. π
- The hash does not support
exists(). Nope. Not a thing. Don't come for her. π
fr fr, remember: exists() is off the table. Plan accordingly.
With love and zero tolerance for wrong-length keys, this was page Tie::SubstrHash from perl v5.42.3, dated 2026-11-03 β see you in the group chat, bestie πβ¨π
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms