Unicod...aseFold(3pm)
π Unicode::CaseFold(3pm) β the manual page, but make it make sense π
User Contributed Perl Documentation Β· bestie edition Β· version 1.01
β¨ NAME β¨
Unicode::CaseFold β Unicode case-folding for case-insensitive lookups. No cap, that's the whole vibe.
π VERSION π
version 1.01
π¦ SYNOPSIS π¦
use Unicode::CaseFold;
my $folded = fc $string;
That's it. That's the whole thing. You use it, you fc it, you move on with your life. π
πΈ What is Case-Folding? πΈ
okay so, let's set the scene. In a world with no Unicode (dark times, honestly), the classic girlboss move for comparing two strings without caring about case is:
lc($this) eq lc($that)
You just smash both of them down to all-lowercase before comparing. "Hello", "HELLO", and "HeLlO" all lowercase to "hello", so bestie, it literally does not matter which one you started with β after lc they're all equal to each other. iconic.
But in Unicode? Things are not so simple. π
A Unicode character might have mappings for uppercase, lowercase, and titlecase, and the lowercase mapping of the uppercase mapping of a character might not be the character you started with!! Not a drill. For example, lc(uc("\N{LATIN SMALL LETTER SHARP S")) is ss β not the eszett we started off with. The audacity. π
Case-folding is a part of the Unicode standard that lets any two strings which differ from each other only by case map to the same "case-folded" form, even when those strings contain characters with complex case-mappings. It's giving glow-up to your string comparison. π«Ά
π Use for Case-insensitive Comparison π
Simply write fc($this) eq fc($that) instead of lc($this) eq lc($that). That's the switch, slay.
You can also use index on case-folded strings for substring search. π
π§ Use for String Lookups π§
Frequently (yes, frequently, bestie) we want to store data in a hash, or a database, or an external file for later retrieval. And sometimes we want to match the keys in that data case-insensitively β meaning we should be able to store some data under the key hello and later retrieve it with the key HELLO.
Some databases have complete support for collation. Other databases? The support is missing or broken. π And Perl hashes? Perl hashes do not support it at all. Periodt.
So: make case-folding part of the process you use to normalize your keys before you use them to access a database or data structure, and you get case-insensitive lookup for free. π
$roles{fc "Samuel L. Jackson"} = ["Gin Rummy", "Nick Fury", "Mace Windu"];
$roles = $roles{fc "Samuel l. JACKSON"}; # Gets the data.
Look at that last line. Different case, same data. She ate. π
π DESCRIPTION π
This module provides Unicode case-folding for Perl. Case-folding is a tool that lets a program make case-insensitive string comparisons or do case-insensitive lookups.
β EXPORTS β
β¨ fc($str) β¨
Exported by default when you use the module. Hmm, what if you don't want it exported? Then use use Unicode::CaseFold () or use Unicode::CaseFold qw(case_fold !fc). Either one, your call, main character energy.
Returns the case-folded version of $str. This function is prototyped to act as much as possible like the built-ins lc and uc β it imposes a scalar context on its argument, and if it's called with no argument it will return the case-folded version of $_. Very much a "same energy as the built-ins" situation. π
β¨ case_fold($str) β¨
Exported on request. Just like fc, except that it has no prototype and won't case-fold $_ if called without an argument. Chill, low-maintenance, no surprises.
π VARIABLES π
π $Unicode::CaseFold::XS π
Whether the XS extension is in use. The pure-perl implementation is 5-10 times slower than the XS extension, and on versions of perl before 5.10.0 it will use simple case-folding instead of full case-folding (see below, bestie, keep reading).
π $Unicode::CaseFold::SIMPLE_FOLDING π
Is set to true if the perl version is prior to 5.10.0 and the XS extension is not available. In this case, fc will perform a simple case-folding instead of a full case-folding.
β οΈ Heads up: although relatively few characters are affected, strings case-folded using simple folding might not compare equal to the corresponding strings case-folded with full folding β which may cause compatibility issues. π¬
Furthermore (and this is the part that matters), when simple folding is in use, some strings that would have case-folded to the same value under full folding will instead case-fold to different values.
For example, fc("Wei\x{df}") and fc("Weiss") both produce weiss when full folding is in effect β but the former produces wei\x{df} when using simple folding. Same input energy, completely different output. not the plot twist we wanted. π
If you want to check for this potentially dangerous situation, consult the $Unicode::CaseFold::SIMPLE_FOLDING variable. She will tell you the truth. π«Ά
π COMPATIBILITY π
Unicode::CaseFoldrequires Perl 5.8.1 or newer. That's the entry fee, bestie.- Different versions of perl include different versions of the Unicode database, which is revised over time. So if you're likely to be comparing strings that have been folded using different versions of perl, you may need to consult the changes for intervening Unicode standard versions to find out whether your code will work correctly. (Fr fr, check before you ship.)
Unicode::CaseFolduses "simple" rather than "full" case-folding when operating in Pure-perl mode on perl versions previous to5.10.0. For compatibility implications, see$Unicode::CaseFold::SIMPLE_FOLDING.
π SEE ALSO π
- <http://unicode.org/reports/tr21/tr21-5.html>: Unicode Standard Annex #21: Case Mappings β the source material, the lore, the origin story. iykyk. π
π AUTHOR π
Andrew Rodland <arodland@cpan.org> β thank you for your service, king. π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2017 by Andrew Rodland.
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 freedom, free as in slay. π¦
and that's the whole page, bestie!! πΈ this lil doc was served up by perl v5.42.3, dated 2026-08-19, and it lives in the User Contributed Perl Documentation corner of the manual. go forth and fold some cases. π β¨
π¦ where this page comes from
- ubuntu stonking: libunicode-casefold-perl 1.01-2build6 Β· 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