EXTUTILS::MAKEMAKER::LOCALE(3perl)
β¨ NAME β¨
bestie, welcome to ExtUtils::MakeMaker::Locale β it's the bundled Encode::Locale, and it's literally here to make your Unicode life not a whole tragedy π«Ά (this is the page from the Perl Programmers Reference Guide, and it's giving very main character energy π
)
πΈ SYNOPSIS πΈ
use Encode::Locale;
use Encode;
$string = decode(locale => $bytes);
$bytes = encode(locale => $string);
if (-t) {
binmode(STDIN, ":encoding(console_in)");
binmode(STDOUT, ":encoding(console_out)");
binmode(STDERR, ":encoding(console_out)");
}
# Processing file names passed in as arguments
my $uni_filename = decode(locale => $ARGV[0]);
open(my $fh, "<", encode(locale_fs => $uni_filename))
|| die "Can't open '$uni_filename': $!";
binmode($fh, ":encoding(locale)");
...
like, that's the whole vibe. copy it, slay it, ship it β¨
π DESCRIPTION π
okay so picture this: in SO many apps it's the move to just let Perl use Unicode for the strings it's processing. but here's the tea β most of the interfaces Perl has to the outside world are still byte based. π so programs gotta decode the byte strings coming in from outside, and encode them again on the way back out. that's just the gig, no cap.
the POSIX locale system is what specifies both the language conventions the user asked for AND the preferred character set to consume and output. the Encode::Locale module goes and looks up the charset and encoding (which the locale people call a CODESET, iykyk) and then arranges for the Encode module to know this encoding under the name locale. what that means for you: bytes you got from the environment can be converted into Unicode strings by calling Encode::encode(locale => $bytes), and converted back again with Encode::decode(locale => $string). boom. iconic. π
where the file system interfaces pass file names in and out of the program we also gotta be careful. the trend rn is for operating systems to use a fixed file encoding that doesn't actually depend on the locale; and this module figures out the most appropriate encoding for file names. the Encode module will know this encoding under the name locale_fs. for traditional Unix systems this will just be an alias to the same encoding as locale. easy.
and for programs running in a terminal window (some systems call it a "Console" β cute), the locale encoding is usually a good choice for what to expect as input and output. some systems let us query the encoding set for the terminal and Encode::Locale will do that if it's available and make these encodings known under the Encode aliases console_in and console_out. for systems where we can't determine the terminal encoding, these will be aliased as the same encoding as locale. the advice: use console_in for input you know comes from the terminal, and console_out for output to the terminal. periodt.
in addition to arranging all those Encode aliases, the following functions and variables are also provided:
decode_argv( )decode_argv( Encode::FB_CROAK )
this will decode the command line arguments to perl (the @ARGV array) in-place. very on-the-spot of it.
the function will by default replace characters that can't be decoded by "\x{FFFD}", the Unicode replacement character.
any argument you hand it gets passed as CHECK to the underlying Encode::decode() call. pass the value Encode::FB_CROAK if you want the decoding to croak when not all the command line arguments can be decoded. see "Handling Malformed Data" in Encode for the deets on the other options for CHECK. π
env( $uni_key )env( $uni_key => $uni_value )
an interface to get/set environment variables. returns the current value as a Unicode string. the $uni_key and $uni_value arguments are expected to be Unicode strings too, bestie. and passing undef as $uni_value deletes the environment variable named $uni_key. poof, gone. π
the returned value will have the characters that can't be decoded replaced by "\x{FFFD}", the Unicode replacement character.
there is no interface to request alternative CHECK behavior like there is for decode_argv(). if you need that, you need to call encode/decode yourself. for example:
my $key = Encode::encode(locale => $uni_key, Encode::FB_CROAK);
my $uni_value = Encode::decode(locale => $ENV{$key}, Encode::FB_CROAK);
reinit( )reinit( $encoding )
reinitialize the encodings from the locale. you wanna call this function if you changed anything in the environment that might influence the locale. π
this function will croak if the determined encoding isn't recognized by the Encode module. scream, but make it a croak.
with argument, force the $ENCODING_... variables to be set to the given value.
$ENCODING_LOCALE
the encoding name determined to be suitable for the current locale. Encode knows this encoding as locale.
$ENCODING_LOCALE_FS
the encoding name determined to be suitable for file system interfaces involving file names. Encode knows this encoding as locale_fs.
$ENCODING_CONSOLE_IN$ENCODING_CONSOLE_OUT
the encodings to be used for reading and writing output to a console. Encode knows these encodings as console_in and console_out.
π NOTES π
this table summarizes the mapping of the encodings that the Encode::Locale module sets up:
Encode | | |
Alias | Windows | Mac OS X | POSIX
------------+---------+--------------+------------
locale | ANSI | nl_langinfo | nl_langinfo
locale_fs | ANSI | UTF-8 | nl_langinfo
console_in | OEM | nl_langinfo | nl_langinfo
console_out | OEM | nl_langinfo | nl_langinfo
πͺ Windows
Windows has basically 2 sets of APIs. a wide API (based on passing UTF-16 strings) and a byte based API based on a character set called ANSI. the regular Perl interfaces to the OS currently only use the ANSI APIs. and unfortunately, ANSI is not a single character set. π
the encoding that corresponds to ANSI varies between different editions of Windows. for many western editions of Windows, ANSI corresponds to CP-1252, which is a character set similar to ISO-8859-1. conceptually the ANSI character set is a similar concept to the POSIX locale CODESET, so this module figures out what the ANSI code page is and makes it available as $ENCODING_LOCALE and the locale Encoding alias. got it? iconic.
Windows systems also operate with another byte based character set. it's called the OEM code page. this is the encoding that the Console takes as input and output. it's common for the OEM code page to differ from the ANSI code page. yeah, two whole code pages, it's giving chaos but okay. π
π Mac OS X
on Mac OS X the file system encoding is always UTF-8, while the locale can otherwise be set up as normal for POSIX systems.
file names on Mac OS X will at the OS-level be converted to NFD-form. a file created by passing a NFC-filename will come in NFD-form from readdir(). see Unicode::Normalize for details of NFD/NFC. β¨
actually, Apple does not follow the Unicode NFD standard, since not all character ranges are decomposed. the claim is that this avoids problems with round trip conversions from old Mac text encodings. see Encode::UTF8Mac for details. π
π§ POSIX (Linux and other Unixes)
file systems might vary in what encoding is to be used for filenames. since this module has no way to actually figure out what is correct, it goes with the best guess, which is to assume filenames are encoded according to the current locale. users are advised to always specify UTF-8 as the locale charset. not a suggestion, bestie. π
π SEE ALSO π
I18N::Langinfo, Encode, Term::Encoding
π AUTHOR π
Copyright 2010 Gisle Aas <gisle@aas.no>.
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π this was ExtUti...:Locale(3perl), straight out of perl v5.44.0, dated 2026-10-17. go forth and decode responsibly π
β¨π¦
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND 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