Hash::Case(3pm)

πŸ’– Hash::Case πŸ’– (the base class for hashes with key-casing requirements)

okay so this is the Hash::Case(3pm) page from the User Contributed Perl Documentation, and bestie, it's literally about hashes that care deeply about how your keys are cased. slay.


🌸 INHERITANCE 🌸

  • Hash::Case is a Tie::StdHash
  • Hash::Case is extended by Hash::Case::Lower, Hash::Case::Preserve, Hash::Case::Upper

like, it's the parent friend and these three are its iconic children πŸ’…


✨ SYNOPSIS ✨

use Hash::Case::Lower;
tie my(%lchash), 'Hash::Case::Lower';
$lchash{StraNGeKeY} = 3;
print keys %lchash;  # strangekey

(tied %lchash)->addPairs(key => value, ...);
(tied %lchash)->addHashData(\%data);
(tied %lchash)->setHash(\%replacement);

see how StraNGeKeY walked in and left as strangekey? that's the whole vibe πŸ¦‹


πŸ‘‘ DESCRIPTION πŸ‘‘

Hash::Case is the base class for a bunch of classes that tie special treatment for the casing of keys. but β€” and this is the important part β€” be aware of the differences in implementation, fr fr:

  • Lower and Upper are tied native hashes: these hashes have no need for hidden fields or other assisting data structures. zero baggage, main character energy.
  • A case Preserve hash will actually create three hashes. not me, that's just what it does 😭

The following strategies are implemented:

  • Hash::Case::Lower (native hash) β€” keys are always considered lower case. the internals of this module translate any incoming key to lower case before it is used. it's giving lowercase supremacy.
  • Hash::Case::Upper (native hash) β€” like the ::Lower, but then all keys are always translated into upper case. this module can be of use for some databases, which do translate everything to capitals as well. to avoid confusion, you may want to have your own internal Perl hash do this as well. LOUD KEYS ONLY πŸ”₯
  • Hash::Case::Preserve β€” the actual casing is ignored, but not forgotten. it remembers. it's that friend. πŸŽ€

πŸ’… METHODS πŸ’…

🫢 Constructors

  • tie %hash, $class, [$values,] %options β€” tie the %hash with the $class (package which extends Hash::Case). the %options differ per implementation, so read the manual page for the package you actually use, bestie. the optional $values is a reference to an ARRAY (containing key-value PAIRS) or a HASH: they fill in the initial %hash.

Β» example:

my %x;
tie %x, 'Hash::Case::Lower';
$x{Upper} = 3;
print keys %x;       # 'upper'

my @y = (ABC => 3, DeF => 4);
tie %x, 'Hash::Case::Lower', \@y;
print keys %x;       # 'abc' 'def'

my %z = (ABC => 3, DeF => 4);
tie %x, 'Hash::Case::Lower', \%z;

look at that array-vs-hash flex, we love a versatile constructor πŸ’–

🧚 Hidden object access

Besides all the usual HASH actions which are implemented for the tied %hash, you can also call methods on the tied() object. sneaky but iconic.

  • $obj->addHashData(\%data) β€” add the %data to the created tied hash. the existing values in the hash remain, and the keys are adapted to the needs of the casing. nothing gets yeeted, everything just gets a case makeover ✨
  • $obj->addPairs(@pairs) β€” specify an even length list of alternating key and value to be stored in the hash. even length, okay? the universe demands pairs πŸ“
  • $obj->setHash(\%data) β€” the functionality differs for native and wrapper hashes:
    • for native hashes, this is the same as first clearing the hash, and then a call to addHashData().
    • wrapper hashes will use the hash you specify here to store the data, and re-create the mapping hash. πŸ¦‹
ngl, the native-vs-wrapper split here is the one spot where you gotta actually read carefully. it's giving two very different behaviours under one method name 😭

🌈 SEE ALSO 🌈

This module is part of Hash-Case version 1.07, built on January 26, 2026. Website: http://perl.overmeer.net/CPAN/ β€” go visit, iykyk πŸ’œ


πŸŽ€ LICENSE πŸŽ€

For contributors see file ChangeLog.

This software is copyright (c) 2002-2026 by Mark Overmeer.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in go off, king πŸ‘‘


and that's the page, bestie! this lil doc is from perl v5.40.1, dated 2026-01-26, and it's the Hash::Case(3pm) manpage β€” now go tie some hashes and case those keys however you want πŸ’–

πŸ“¦ where this page comes from