{
    "mode": "perldoc",
    "parameter": "Encode::Locale",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Encode%3A%3ALocale/json",
    "generated": "2026-06-12T15:27:23Z",
    "synopsis": "use Encode::Locale;\nuse Encode;\n$string = decode(locale => $bytes);\n$bytes = encode(locale => $string);\nif (-t) {\nbinmode(STDIN, \":encoding(consolein)\");\nbinmode(STDOUT, \":encoding(consoleout)\");\nbinmode(STDERR, \":encoding(consoleout)\");\n}\n# Processing file names passed in as arguments\nmy $unifilename = decode(locale => $ARGV[0]);\nopen(my $fh, \"<\", encode(localefs => $unifilename))\n|| die \"Can't open '$unifilename': $!\";\nbinmode($fh, \":encoding(locale)\");\n...",
    "sections": {
        "NAME": {
            "content": "Encode::Locale - Determine the locale encoding\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Encode::Locale;\nuse Encode;\n\n$string = decode(locale => $bytes);\n$bytes = encode(locale => $string);\n\nif (-t) {\nbinmode(STDIN, \":encoding(consolein)\");\nbinmode(STDOUT, \":encoding(consoleout)\");\nbinmode(STDERR, \":encoding(consoleout)\");\n}\n\n# Processing file names passed in as arguments\nmy $unifilename = decode(locale => $ARGV[0]);\nopen(my $fh, \"<\", encode(localefs => $unifilename))\n|| die \"Can't open '$unifilename': $!\";\nbinmode($fh, \":encoding(locale)\");\n...\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "In many applications it's wise to let Perl use Unicode for the strings it processes. Most of the\ninterfaces Perl has to the outside world are still byte based. Programs therefore need to decode\nbyte strings that enter the program from the outside and encode them again on the way out.\n\nThe POSIX locale system is used to specify both the language conventions requested by the user\nand the preferred character set to consume and output. The \"Encode::Locale\" module looks up the\ncharset and encoding (called a CODESET in the locale jargon) and arranges for the Encode module\nto know this encoding under the name \"locale\". It means bytes obtained from the environment can\nbe converted to Unicode strings by calling \"Encode::encode(locale => $bytes)\" and converted back\nagain with \"Encode::decode(locale => $string)\".\n\nWhere file systems interfaces pass file names in and out of the program we also need care. The\ntrend is for operating systems to use a fixed file encoding that don't actually depend on the\nlocale; and this module determines the most appropriate encoding for file names. The Encode\nmodule will know this encoding under the name \"localefs\". For traditional Unix systems this\nwill be an alias to the same encoding as \"locale\".\n\nFor programs running in a terminal window (called a \"Console\" on some systems) the \"locale\"\nencoding is usually a good choice for what to expect as input and output. Some systems allows us\nto query the encoding set for the terminal and \"Encode::Locale\" will do that if available and\nmake these encodings known under the \"Encode\" aliases \"consolein\" and \"consoleout\". For\nsystems where we can't determine the terminal encoding these will be aliased as the same\nencoding as \"locale\". The advice is to use \"consolein\" for input known to come from the\nterminal and \"consoleout\" for output to the terminal.\n\nIn addition to arranging for various Encode aliases the following functions and variables are\nprovided:\n",
            "subsections": [
                {
                    "name": "decode_argv",
                    "content": ""
                },
                {
                    "name": "decode_argv",
                    "content": "This will decode the command line arguments to perl (the @ARGV array) in-place.\n\nThe function will by default replace characters that can't be decoded by \"\\x{FFFD}\", the\nUnicode replacement character.\n\nAny argument provided is passed as CHECK to underlying Encode::decode() call. Pass the value\n\"Encode::FBCROAK\" to have the decoding croak if not all the command line arguments can be\ndecoded. See \"Handling Malformed Data\" in Encode for details on other options for CHECK.\n"
                },
                {
                    "name": "env",
                    "content": ""
                },
                {
                    "name": "env",
                    "content": "Interface to get/set environment variables. Returns the current value as a Unicode string.\nThe $unikey and $univalue arguments are expected to be Unicode strings as well. Passing\n\"undef\" as $univalue deletes the environment variable named $unikey.\n\nThe returned value will have the characters that can't be decoded replaced by \"\\x{FFFD}\",\nthe Unicode replacement character.\n\nThere is no interface to request alternative CHECK behavior as for decodeargv(). If you\nneed that you need to call encode/decode yourself. For example:\n\nmy $key = Encode::encode(locale => $unikey, Encode::FBCROAK);\nmy $univalue = Encode::decode(locale => $ENV{$key}, Encode::FBCROAK);\n"
                },
                {
                    "name": "reinit",
                    "content": ""
                },
                {
                    "name": "reinit",
                    "content": "Reinitialize the encodings from the locale. You want to call this function if you changed\nanything in the environment that might influence the locale.\n\nThis function will croak if the determined encoding isn't recognized by the Encode module.\n\nWith argument force $ENCODING... variables to set to the given value.\n\n$ENCODINGLOCALE\nThe encoding name determined to be suitable for the current locale. Encode know this\nencoding as \"locale\".\n\n$ENCODINGLOCALEFS\nThe encoding name determined to be suitable for file system interfaces involving file names.\nEncode know this encoding as \"localefs\".\n\n$ENCODINGCONSOLEIN\n$ENCODINGCONSOLEOUT\nThe encodings to be used for reading and writing output to the a console. Encode know these\nencodings as \"consolein\" and \"consoleout\".\n"
                }
            ]
        },
        "NOTES": {
            "content": "This table summarizes the mapping of the encodings set up by the \"Encode::Locale\" module:\n\nEncode      |         |              |\nAlias       | Windows | Mac OS X     | POSIX\n------------+---------+--------------+------------\nlocale      | ANSI    | nllanginfo  | nllanginfo\nlocalefs   | ANSI    | UTF-8        | nllanginfo\nconsolein  | OEM     | nllanginfo  | nllanginfo\nconsoleout | OEM     | nllanginfo  | nllanginfo\n",
            "subsections": [
                {
                    "name": "Windows",
                    "content": "Windows has basically 2 sets of APIs. A wide API (based on passing UTF-16 strings) and a byte\nbased API based a character set called ANSI. The regular Perl interfaces to the OS currently\nonly uses the ANSI APIs. Unfortunately ANSI is not a single character set.\n\nThe encoding that corresponds to ANSI varies between different editions of Windows. For many\nwestern editions of Windows ANSI corresponds to CP-1252 which is a character set similar to\nISO-8859-1. Conceptually the ANSI character set is a similar concept to the POSIX locale CODESET\nso this module figures out what the ANSI code page is and make this available as\n$ENCODINGLOCALE and the \"locale\" Encoding alias.\n\nWindows systems also operate with another byte based character set. It's called the OEM code\npage. This is the encoding that the Console takes as input and output. It's common for the OEM\ncode page to differ from the ANSI code page.\n"
                },
                {
                    "name": "Mac OS X",
                    "content": "On Mac OS X the file system encoding is always UTF-8 while the locale can otherwise be set up as\nnormal for POSIX systems.\n\nFile names on Mac OS X will at the OS-level be converted to NFD-form. A file created by passing\na NFC-filename will come in NFD-form from readdir(). See Unicode::Normalize for details of\nNFD/NFC.\n\nActually, Apple does not follow the Unicode NFD standard since not all character ranges are\ndecomposed. The claim is that this avoids problems with round trip conversions from old Mac text\nencodings. See Encode::UTF8Mac for details.\n\nPOSIX (Linux and other Unixes)\nFile systems might vary in what encoding is to be used for filenames. Since this module has no\nway to actually figure out what the is correct it goes with the best guess which is to assume\nfilenames are encoding according to the current locale. Users are advised to always specify\nUTF-8 as the locale charset.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "I18N::Langinfo, Encode, Term::Encoding\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Copyright 2010 Gisle Aas <gisle@aas.no>.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "Encode::Locale - Determine the locale encoding",
    "flags": [],
    "examples": [],
    "see_also": []
}