{
    "content": [
        {
            "type": "text",
            "text": "# Encode (man)\n\n## NAME\n\nEncode - character encodings in Perl\n\n## SYNOPSIS\n\nuse Encode qw(decode encode);\n$characters = decode('UTF-8', $octets,     Encode::FBCROAK);\n$octets     = encode('UTF-8', $characters, Encode::FBCROAK);\n\n## DESCRIPTION\n\nThe \"Encode\" module provides the interface between Perl strings and the rest of the system.\nPerl strings are sequences of characters.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS** (1 subsections)\n- **DESCRIPTION**\n- **THE PERL ENCODING API** (11 subsections)\n- **SEE ALSO**\n- **MAINTAINER**\n- **COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Encode",
        "section": "",
        "mode": "man",
        "summary": "Encode - character encodings in Perl",
        "synopsis": "use Encode qw(decode encode);\n$characters = decode('UTF-8', $octets,     Encode::FBCROAK);\n$octets     = encode('UTF-8', $characters, Encode::FBCROAK);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": [
                    {
                        "name": "Table of Contents",
                        "lines": 12
                    }
                ]
            },
            {
                "name": "DESCRIPTION",
                "lines": 35,
                "subsections": []
            },
            {
                "name": "THE PERL ENCODING API",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Basic methods",
                        "lines": 168
                    },
                    {
                        "name": "Listing available encodings",
                        "lines": 18
                    },
                    {
                        "name": "Defining Aliases",
                        "lines": 21
                    },
                    {
                        "name": "Finding IANA Character Set Registry names",
                        "lines": 13
                    },
                    {
                        "name": "Encoding via PerlIO",
                        "lines": 43
                    },
                    {
                        "name": "Handling Malformed Data",
                        "lines": 97
                    },
                    {
                        "name": "coderef for CHECK",
                        "lines": 17
                    },
                    {
                        "name": "Defining Encodings",
                        "lines": 11
                    },
                    {
                        "name": "The UTF8 flag",
                        "lines": 32
                    },
                    {
                        "name": "Messing with Perl's Internals",
                        "lines": 43
                    },
                    {
                        "name": "UTF-8 vs. utf8 vs. UTF8",
                        "lines": 67
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "MAINTAINER",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 8,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Encode - character encodings in Perl\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Encode qw(decode encode);\n$characters = decode('UTF-8', $octets,     Encode::FBCROAK);\n$octets     = encode('UTF-8', $characters, Encode::FBCROAK);\n",
                "subsections": [
                    {
                        "name": "Table of Contents",
                        "content": "Encode consists of a collection of modules whose details are too extensive to fit in one\ndocument.  This one itself explains the top-level APIs and general topics at a glance.  For\nother topics and more details, see the documentation for these modules:\n\nEncode::Alias - Alias definitions to encodings\nEncode::Encoding - Encode Implementation Base Class\nEncode::Supported - List of Supported Encodings\nEncode::CN - Simplified Chinese Encodings\nEncode::JP - Japanese Encodings\nEncode::KR - Korean Encodings\nEncode::TW - Traditional Chinese Encodings\n"
                    }
                ]
            },
            "DESCRIPTION": {
                "content": "The \"Encode\" module provides the interface between Perl strings and the rest of the system.\nPerl strings are sequences of characters.\n\nThe repertoire of characters that Perl can represent is a superset of those defined by the\nUnicode Consortium. On most platforms the ordinal values of a character as returned by\n\"ord(S)\" is the Unicode codepoint for that character. The exceptions are platforms where the\nlegacy encoding is some variant of EBCDIC rather than a superset of ASCII; see perlebcdic.\n\nDuring recent history, data is moved around a computer in 8-bit chunks, often called \"bytes\"\nbut also known as \"octets\" in standards documents.  Perl is widely used to manipulate data of\nmany types: not only strings of characters representing human or computer languages, but also\n\"binary\" data, being the machine's representation of numbers, pixels in an image, or just\nabout anything.\n\nWhen Perl is processing \"binary data\", the programmer wants Perl to process \"sequences of\nbytes\". This is not a problem for Perl: because a byte has 256 possible values, it easily\nfits in Perl's much larger \"logical character\".\n\nThis document mostly explains the how. perlunitut and perlunifaq explain the why.\n\nTERMINOLOGY\ncharacter\n\nA character in the range 0 .. 232-1 (or more); what Perl's strings are made of.\n\nbyte\n\nA character in the range 0..255; a special case of a Perl character.\n\noctet\n\n8 bits of data, with ordinal values 0..255; term for bytes passed to or from a non-Perl\ncontext, such as a disk file, standard I/O stream, database, command-line argument,\nenvironment variable, socket etc.\n",
                "subsections": []
            },
            "THE PERL ENCODING API": {
                "content": "",
                "subsections": [
                    {
                        "name": "Basic methods",
                        "content": "encode\n\n$octets  = encode(ENCODING, STRING[, CHECK])\n\nEncodes the scalar value STRING from Perl's internal form into ENCODING and returns a\nsequence of octets.  ENCODING can be either a canonical name or an alias.  For encoding names\nand aliases, see \"Defining Aliases\".  For CHECK, see \"Handling Malformed Data\".\n\nCAVEAT: the input scalar STRING might be modified in-place depending on what is set in CHECK.\nSee \"LEAVESRC\" if you want your inputs to be left unchanged.\n\nFor example, to convert a string from Perl's internal format into ISO-8859-1, also known as\nLatin1:\n\n$octets = encode(\"iso-8859-1\", $string);\n\nCAVEAT: When you run \"$octets = encode(\"UTF-8\", $string)\", then $octets might not be equal to\n$string.  Though both contain the same data, the UTF8 flag for $octets is always off.  When\nyou encode anything, the UTF8 flag on the result is always off, even when it contains a\ncompletely valid UTF-8 string. See \"The UTF8 flag\" below.\n\nIf the $string is \"undef\", then \"undef\" is returned.\n\n\"str2bytes\" may be used as an alias for \"encode\".\n\ndecode\n\n$string = decode(ENCODING, OCTETS[, CHECK])\n\nThis function returns the string that results from decoding the scalar value OCTETS, assumed\nto be a sequence of octets in ENCODING, into Perl's internal form.  As with encode(),\nENCODING can be either a canonical name or an alias. For encoding names and aliases, see\n\"Defining Aliases\"; for CHECK, see \"Handling Malformed Data\".\n\nCAVEAT: the input scalar OCTETS might be modified in-place depending on what is set in CHECK.\nSee \"LEAVESRC\" if you want your inputs to be left unchanged.\n\nFor example, to convert ISO-8859-1 data into a string in Perl's internal format:\n\n$string = decode(\"iso-8859-1\", $octets);\n\nCAVEAT: When you run \"$string = decode(\"UTF-8\", $octets)\", then $string might not be equal to\n$octets.  Though both contain the same data, the UTF8 flag for $string is on.  See \"The UTF8\nflag\" below.\n\nIf the $string is \"undef\", then \"undef\" is returned.\n\n\"bytes2str\" may be used as an alias for \"decode\".\n\nfindencoding\n\n[$obj =] findencoding(ENCODING)\n\nReturns the encoding object corresponding to ENCODING.  Returns \"undef\" if no matching\nENCODING is find.  The returned object is what does the actual encoding or decoding.\n\n$string = decode($name, $bytes);\n\nis in fact\n\n$string = do {\n$obj = findencoding($name);\ncroak qq(encoding \"$name\" not found) unless ref $obj;\n$obj->decode($bytes);\n};\n\nwith more error checking.\n\nYou can therefore save time by reusing this object as follows;\n\nmy $enc = findencoding(\"iso-8859-1\");\nwhile(<>) {\nmy $string = $enc->decode($);\n... # now do something with $string;\n}\n\nBesides \"decode\" and \"encode\", other methods are available as well.  For instance, \"name()\"\nreturns the canonical name of the encoding object.\n\nfindencoding(\"latin1\")->name; # iso-8859-1\n\nSee Encode::Encoding for details.\n\nfindmimeencoding\n\n[$obj =] findmimeencoding(MIMEENCODING)\n\nReturns the encoding object corresponding to MIMEENCODING.  Acts same as \"findencoding()\"\nbut \"mimename()\" of returned object must match to MIMEENCODING.  So as opposite of\n\"findencoding()\" canonical names and aliases are not used when searching for object.\n\nfindmimeencoding(\"utf8\"); # returns undef because \"utf8\" is not valid I<MIMEENCODING>\nfindmimeencoding(\"utf-8\"); # returns encode object \"utf-8-strict\"\nfindmimeencoding(\"UTF-8\"); # same as \"utf-8\" because I<MIMEENCODING> is case insensitive\nfindmimeencoding(\"utf-8-strict\"); returns undef because \"utf-8-strict\" is not valid I<MIMEENCODING>\n\nfromto\n\n[$length =] fromto($octets, FROMENC, TOENC [, CHECK])\n\nConverts in-place data between two encodings. The data in $octets must be encoded as octets\nand not as characters in Perl's internal format. For example, to convert ISO-8859-1 data into\nMicrosoft's CP1250 encoding:\n\nfromto($octets, \"iso-8859-1\", \"cp1250\");\n\nand to convert it back:\n\nfromto($octets, \"cp1250\", \"iso-8859-1\");\n\nBecause the conversion happens in place, the data to be converted cannot be a string\nconstant: it must be a scalar variable.\n\n\"fromto()\" returns the length of the converted string in octets on success, and \"undef\" on\nerror.\n\nCAVEAT: The following operations may look the same, but are not:\n\nfromto($data, \"iso-8859-1\", \"UTF-8\"); #1\n$data = decode(\"iso-8859-1\", $data);  #2\n\nBoth #1 and #2 make $data consist of a completely valid UTF-8 string, but only #2 turns the\nUTF8 flag on.  #1 is equivalent to:\n\n$data = encode(\"UTF-8\", decode(\"iso-8859-1\", $data));\n\nSee \"The UTF8 flag\" below.\n\nAlso note that:\n\nfromto($octets, $from, $to, $check);\n\nis equivalent to:\n\n$octets = encode($to, decode($from, $octets), $check);\n\nYes, it does not respect the $check during decoding.  It is deliberately done that way.  If\nyou need minute control, use \"decode\" followed by \"encode\" as follows:\n\n$octets = encode($to, decode($from, $octets, $checkfrom), $checkto);\n\nencodeutf8\n\n$octets = encodeutf8($string);\n\nWARNING: This function can produce invalid UTF-8!  Do not use it for data exchange.  Unless\nyou want Perl's older \"lax\" mode, prefer \"$octets = encode(\"UTF-8\", $string)\".\n\nEquivalent to \"$octets = encode(\"utf8\", $string)\".  The characters in $string are encoded in\nPerl's internal format, and the result is returned as a sequence of octets.  Because all\npossible characters in Perl have a (loose, not strict) utf8 representation, this function\ncannot fail.\n\ndecodeutf8\n\n$string = decodeutf8($octets [, CHECK]);\n\nWARNING: This function accepts invalid UTF-8!  Do not use it for data exchange.  Unless you\nwant Perl's older \"lax\" mode, prefer \"$string = decode(\"UTF-8\", $octets [, CHECK])\".\n\nEquivalent to \"$string = decode(\"utf8\", $octets [, CHECK])\".  The sequence of octets\nrepresented by $octets is decoded from (loose, not strict) utf8 into a sequence of logical\ncharacters.  Because not all sequences of octets are valid not strict utf8, it is quite\npossible for this function to fail.  For CHECK, see \"Handling Malformed Data\".\n\nCAVEAT: the input $octets might be modified in-place depending on what is set in CHECK. See\n\"LEAVESRC\" if you want your inputs to be left unchanged.\n"
                    },
                    {
                        "name": "Listing available encodings",
                        "content": "use Encode;\n@list = Encode->encodings();\n\nReturns a list of canonical names of available encodings that have already been loaded.  To\nget a list of all available encodings including those that have not yet been loaded, say:\n\n@allencodings = Encode->encodings(\":all\");\n\nOr you can give the name of a specific module:\n\n@withjp = Encode->encodings(\"Encode::JP\");\n\nWhen \"\"::\"\" is not in the name, \"\"Encode::\"\" is assumed.\n\n@ebcdic = Encode->encodings(\"EBCDIC\");\n\nTo find out in detail which encodings are supported by this package, see Encode::Supported.\n"
                    },
                    {
                        "name": "Defining Aliases",
                        "content": "To add a new alias to a given encoding, use:\n\nuse Encode;\nuse Encode::Alias;\ndefinealias(NEWNAME => ENCODING);\n\nAfter that, NEWNAME can be used as an alias for ENCODING.  ENCODING may be either the name of\nan encoding or an encoding object.\n\nBefore you do that, first make sure the alias is nonexistent using \"resolvealias()\", which\nreturns the canonical name thereof.  For example:\n\nEncode::resolvealias(\"latin1\") eq \"iso-8859-1\" # true\nEncode::resolvealias(\"iso-8859-12\")   # false; nonexistent\nEncode::resolvealias($name) eq $name  # true if $name is canonical\n\n\"resolvealias()\" does not need \"use Encode::Alias\"; it can be imported via \"use Encode\nqw(resolvealias)\".\n\nSee Encode::Alias for details.\n"
                    },
                    {
                        "name": "Finding IANA Character Set Registry names",
                        "content": "The canonical name of a given encoding does not necessarily agree with IANA Character Set\nRegistry, commonly seen as \"Content-Type: text/plain; charset=WHATEVER\".  For most cases, the\ncanonical name works, but sometimes it does not, most notably with \"utf-8-strict\".\n\nAs of \"Encode\" version 2.21, a new method \"mimename()\" is therefore added.\n\nuse Encode;\nmy $enc = findencoding(\"UTF-8\");\nwarn $enc->name;      # utf-8-strict\nwarn $enc->mimename; # UTF-8\n\nSee also:  Encode::Encoding\n"
                    },
                    {
                        "name": "Encoding via PerlIO",
                        "content": "If your perl supports \"PerlIO\" (which is the default), you can use a \"PerlIO\" layer to decode\nand encode directly via a filehandle.  The following two examples are fully identical in\nfunctionality:\n\n### Version 1 via PerlIO\nopen(INPUT,  \"< :encoding(shiftjis)\", $infile)\n|| die \"Can't open < $infile for reading: $!\";\nopen(OUTPUT, \"> :encoding(euc-jp)\",  $outfile)\n|| die \"Can't open > $output for writing: $!\";\nwhile (<INPUT>) {   # auto decodes $\nprint OUTPUT;   # auto encodes $\n}\nclose(INPUT)   || die \"can't close $infile: $!\";\nclose(OUTPUT)  || die \"can't close $outfile: $!\";\n\n### Version 2 via fromto()\nopen(INPUT,  \"< :raw\", $infile)\n|| die \"Can't open < $infile for reading: $!\";\nopen(OUTPUT, \"> :raw\",  $outfile)\n|| die \"Can't open > $output for writing: $!\";\n\nwhile (<INPUT>) {\nfromto($, \"shiftjis\", \"euc-jp\", 1);  # switch encoding\nprint OUTPUT;   # emit raw (but properly encoded) data\n}\nclose(INPUT)   || die \"can't close $infile: $!\";\nclose(OUTPUT)  || die \"can't close $outfile: $!\";\n\nIn the first version above, you let the appropriate encoding layer handle the conversion.  In\nthe second, you explicitly translate from one encoding to the other.\n\nUnfortunately, it may be that encodings are not \"PerlIO\"-savvy.  You can check to see whether\nyour encoding is supported by \"PerlIO\" by invoking the \"perliook\" method on it:\n\nEncode::perliook(\"hz\");             # false\nfindencoding(\"euc-cn\")->perliook;  # true wherever PerlIO is available\n\nuse Encode qw(perliook);            # imported upon request\nperliook(\"euc-jp\")\n\nFortunately, all encodings that come with \"Encode\" core are \"PerlIO\"-savvy except for \"hz\"\nand \"ISO-2022-kr\".  For the gory details, see Encode::Encoding and Encode::PerlIO.\n"
                    },
                    {
                        "name": "Handling Malformed Data",
                        "content": "The optional CHECK argument tells \"Encode\" what to do when encountering malformed data.\nWithout CHECK, \"Encode::FBDEFAULT\" (== 0) is assumed.\n\nAs of version 2.12, \"Encode\" supports coderef values for \"CHECK\"; see below.\n\nNOTE: Not all encodings support this feature.  Some encodings ignore the CHECK argument.  For\nexample, Encode::Unicode ignores CHECK and it always croaks on error.\n\nList of CHECK values\nFBDEFAULT\n\nI<CHECK> = Encode::FBDEFAULT ( == 0)\n\nIf CHECK is 0, encoding and decoding replace any malformed character with a substitution\ncharacter.  When you encode, SUBCHAR is used.  When you decode, the Unicode REPLACEMENT\nCHARACTER, code point U+FFFD, is used.  If the data is supposed to be UTF-8, an optional\nlexical warning of warning category \"utf8\" is given.\n\nFBCROAK\n\nI<CHECK> = Encode::FBCROAK ( == 1)\n\nIf CHECK is 1, methods immediately die with an error message.  Therefore, when CHECK is 1,\nyou should trap exceptions with \"eval{}\", unless you really want to let it \"die\".\n\nFBQUIET\n\nI<CHECK> = Encode::FBQUIET\n\nIf CHECK is set to \"Encode::FBQUIET\", encoding and decoding immediately return the portion\nof the data that has been processed so far when an error occurs. The data argument is\noverwritten with everything after that point; that is, the unprocessed portion of the data.\nThis is handy when you have to call \"decode\" repeatedly in the case where your source data\nmay contain partial multi-byte character sequences, (that is, you are reading with a fixed-\nwidth buffer). Here's some sample code to do exactly that:\n\nmy($buffer, $string) = (\"\", \"\");\nwhile (read($fh, $buffer, 256, length($buffer))) {\n$string .= decode($encoding, $buffer, Encode::FBQUIET);\n# $buffer now contains the unprocessed partial character\n}\n\nFBWARN\n\nI<CHECK> = Encode::FBWARN\n\nThis is the same as \"FBQUIET\" above, except that instead of being silent on errors, it\nissues a warning.  This is handy for when you are debugging.\n\nCAVEAT: All warnings from Encode module are reported, independently of pragma warnings\nsettings. If you want to follow settings of lexical warnings configured by pragma warnings\nthen append also check value \"ENCODE::ONLYPRAGMAWARNINGS\". This value is available since\nEncode version 2.99.\n\nFBPERLQQ FBHTMLCREF FBXMLCREF\n\nperlqq mode (CHECK = Encode::FBPERLQQ)\nHTML charref mode (CHECK = Encode::FBHTMLCREF)\nXML charref mode (CHECK = Encode::FBXMLCREF)\n\nFor encodings that are implemented by the \"Encode::XS\" module, \"CHECK\" \"==\"\n\"Encode::FBPERLQQ\" puts \"encode\" and \"decode\" into \"perlqq\" fallback mode.\n\nWhen you decode, \"\\xHH\" is inserted for a malformed character, where HH is the hex\nrepresentation of the octet that could not be decoded to utf8.  When you encode, \"\\x{HHHH}\"\nwill be inserted, where HHHH is the Unicode code point (in any number of hex digits) of the\ncharacter that cannot be found in the character repertoire of the encoding.\n\nThe HTML/XML character reference modes are about the same. In place of \"\\x{HHHH}\", HTML uses\n\"&#NNN;\" where NNN is a decimal number, and XML uses \"&#xHHHH;\" where HHHH is the hexadecimal\nnumber.\n\nIn \"Encode\" 2.10 or later, \"LEAVESRC\" is also implied.\n\nThe bitmask\n\nThese modes are all actually set via a bitmask.  Here is how the \"FBXXX\" constants are laid\nout.  You can import the \"FBXXX\" constants via \"use Encode qw(:fallbacks)\", and you can\nimport the generic bitmask constants via \"use Encode qw(:fallbackall)\".\n\nFBDEFAULT FBCROAK FBQUIET FBWARN  FBPERLQQ\nDIEONERR    0x0001             X\nWARNONERR   0x0002                               X\nRETURNONERR 0x0004                      X        X\nLEAVESRC     0x0008                                        X\nPERLQQ        0x0100                                        X\nHTMLCREF      0x0200\nXMLCREF       0x0400\n\nLEAVESRC\n\nEncode::LEAVESRC\n\nIf the \"Encode::LEAVESRC\" bit is not set but CHECK is set, then the source string to\nencode() or decode() will be overwritten in place.  If you're not interested in this, then\nbitwise-OR it with the bitmask.\n"
                    },
                    {
                        "name": "coderef for CHECK",
                        "content": "As of \"Encode\" 2.12, \"CHECK\" can also be a code reference which takes the ordinal value of\nthe unmapped character as an argument and returns octets that represent the fallback\ncharacter.  For instance:\n\n$ascii = encode(\"ascii\", $utf8, sub{ sprintf \"<U+%04X>\", shift });\n\nActs like \"FBPERLQQ\" but U+XXXX is used instead of \"\\x{XXXX}\".\n\nFallback for \"decode\" must return decoded string (sequence of characters) and takes a list of\nordinal values as its arguments. So for example if you wish to decode octets as UTF-8, and\nuse ISO-8859-15 as a fallback for bytes that are not valid UTF-8, you could write\n\n$str = decode 'UTF-8', $octets, sub {\nmy $tmp = join '', map chr, @;\nreturn decode 'ISO-8859-15', $tmp;\n};\n"
                    },
                    {
                        "name": "Defining Encodings",
                        "content": "To define a new encoding, use:\n\nuse Encode qw(defineencoding);\ndefineencoding($object, CANONICALNAME [, alias...]);\n\nCANONICALNAME will be associated with $object.  The object should provide the interface\ndescribed in Encode::Encoding.  If more than two arguments are provided, additional arguments\nare considered aliases for $object.\n\nSee Encode::Encoding for details.\n"
                    },
                    {
                        "name": "The UTF8 flag",
                        "content": "Before the introduction of Unicode support in Perl, The \"eq\" operator just compared the\nstrings represented by two scalars. Beginning with Perl 5.8, \"eq\" compares two strings with\nsimultaneous consideration of the UTF8 flag. To explain why we made it so, I quote from page\n402 of Programming Perl, 3rd ed.\n\nGoal #1:\nOld byte-oriented programs should not spontaneously break on the old byte-oriented data\nthey used to work on.\n\nGoal #2:\nOld byte-oriented programs should magically start working on the new character-oriented\ndata when appropriate.\n\nGoal #3:\nPrograms should run just as fast in the new character-oriented mode as in the old byte-\noriented mode.\n\nGoal #4:\nPerl should remain one language, rather than forking into a byte-oriented Perl and a\ncharacter-oriented Perl.\n\nWhen Programming Perl, 3rd ed. was written, not even Perl 5.6.0 had been born yet, many\nfeatures documented in the book remained unimplemented for a long time.  Perl 5.8 corrected\nmuch of this, and the introduction of the UTF8 flag is one of them.  You can think of there\nbeing two fundamentally different kinds of strings and string-operations in Perl: one a byte-\noriented mode  for when the internal UTF8 flag is off, and the other a character-oriented\nmode for when the internal UTF8 flag is on.\n\nThis UTF8 flag is not visible in Perl scripts, exactly for the same reason you cannot (or\nrather, you don't have to) see whether a scalar contains a string, an integer, or a floating-\npoint number.   But you can still peek and poke these if you will.  See the next section.\n"
                    },
                    {
                        "name": "Messing with Perl's Internals",
                        "content": "The following API uses parts of Perl's internals in the current implementation.  As such,\nthey are efficient but may change in a future release.\n\nisutf8\n\nisutf8(STRING [, CHECK])\n\n[INTERNAL] Tests whether the UTF8 flag is turned on in the STRING.  If CHECK is true, also\nchecks whether STRING contains well-formed UTF-8.  Returns true if successful, false\notherwise.\n\nTypically only necessary for debugging and testing.  Don't use this flag as a marker to\ndistinguish character and binary data, that should be decided for each variable when you\nwrite your code.\n\nCAVEAT: If STRING has UTF8 flag set, it does NOT mean that STRING is UTF-8 encoded and vice-\nversa.\n\nAs of Perl 5.8.1, utf8 also has the \"utf8::isutf8\" function.\n\nutf8on\n\nutf8on(STRING)\n\n[INTERNAL] Turns the STRING's internal UTF8 flag on.  The STRING is not checked for\ncontaining only well-formed UTF-8.  Do not use this unless you know with absolute certainty\nthat the STRING holds only well-formed UTF-8.  Returns the previous state of the UTF8 flag\n(so please don't treat the return value as indicating success or failure), or \"undef\" if\nSTRING is not a string.\n\nNOTE: For security reasons, this function does not work on tainted values.\n\nutf8off\n\nutf8off(STRING)\n\n[INTERNAL] Turns the STRING's internal UTF8 flag off.  Do not use frivolously.  Returns the\nprevious state of the UTF8 flag, or \"undef\" if STRING is not a string.  Do not treat the\nreturn value as indicative of success or failure, because that isn't what it means: it is\nonly the previous setting.\n\nNOTE: For security reasons, this function does not work on tainted values.\n"
                    },
                    {
                        "name": "UTF-8 vs. utf8 vs. UTF8",
                        "content": "....We now view strings not as sequences of bytes, but as sequences\nof numbers in the range 0 .. 232-1 (or in the case of 64-bit\ncomputers, 0 .. 264-1) -- Programming Perl, 3rd ed.\n\nThat has historically been Perl's notion of UTF-8, as that is how UTF-8 was first conceived\nby Ken Thompson when he invented it. However, thanks to later revisions to the applicable\nstandards, official UTF-8 is now rather stricter than that. For example, its range is much\nnarrower (0 .. 0x10FFFF to cover only 21 bits instead of 32 or 64 bits) and some sequences\nare not allowed, like those used in surrogate pairs, the 31 non-character code points 0xFDD0\n.. 0xFDEF, the last two code points in any plane (0xXXFFFE and 0xXXFFFF), all non-shortest\nencodings, etc.\n\nThe former default in which Perl would always use a loose interpretation of UTF-8 has now\nbeen overruled:\n\nFrom: Larry Wall <larry@wall.org>\nDate: December 04, 2004 11:51:58 JST\nTo: perl-unicode@perl.org\nSubject: Re: Make Encode.pm support the real UTF-8\nMessage-Id: <20041204025158.GA28754@wall.org>\n\nOn Fri, Dec 03, 2004 at 10:12:12PM +0000, Tim Bunce wrote:\n: I've no problem with 'utf8' being perl's unrestricted uft8 encoding,\n: but \"UTF-8\" is the name of the standard and should give the\n: corresponding behaviour.\n\nFor what it's worth, that's how I've always kept them straight in my\nhead.\n\nAlso for what it's worth, Perl 6 will mostly default to strict but\nmake it easy to switch back to lax.\n\nLarry\n\nGot that?  As of Perl 5.8.7, \"UTF-8\" means UTF-8 in its current sense, which is conservative\nand strict and security-conscious, whereas \"utf8\" means UTF-8 in its former sense, which was\nliberal and loose and lax.  \"Encode\" version 2.10 or later thus groks this subtle but\ncritically important distinction between \"UTF-8\" and \"utf8\".\n\nencode(\"utf8\",  \"\\x{FFFFFFFF}\", 1); # okay\nencode(\"UTF-8\", \"\\x{FFFFFFFF}\", 1); # croaks\n\nThis distinction is also important for decoding. In the following, $s stores character\nU+200000, which exceeds UTF-8's allowed range.  $s thus stores an invalid Unicode code point:\n\n$s = decode(\"utf8\", \"\\xf8\\x88\\x80\\x80\\x80\");\n\n\"UTF-8\", by contrast, will either coerce the input to something valid:\n\n$s = decode(\"UTF-8\", \"\\xf8\\x88\\x80\\x80\\x80\"); # U+FFFD\n\n.. or croak:\n\ndecode(\"UTF-8\", \"\\xf8\\x88\\x80\\x80\\x80\", FBCROAK|LEAVESRC);\n\nIn the \"Encode\" module, \"UTF-8\" is actually a canonical name for \"utf-8-strict\".  That hyphen\nbetween the \"UTF\" and the \"8\" is critical; without it, \"Encode\" goes \"liberal\" and (perhaps\noverly-)permissive:\n\nfindencoding(\"UTF-8\")->name # is 'utf-8-strict'\nfindencoding(\"utf-8\")->name # ditto. names are case insensitive\nfindencoding(\"utf8\")->name # ditto. \"\" are treated as \"-\"\nfindencoding(\"UTF8\")->name  # is 'utf8'.\n\nPerl's internal UTF8 flag is called \"UTF8\", without a hyphen. It indicates whether a string\nis internally encoded as \"utf8\", also without a hyphen.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "Encode::Encoding, Encode::Supported, Encode::PerlIO, encoding, perlebcdic, \"open\" in\nperlfunc, perlunicode, perluniintro, perlunifaq, perlunitut utf8, the Perl Unicode Mailing\nList <http://lists.perl.org/list/perl-unicode.html>\n",
                "subsections": []
            },
            "MAINTAINER": {
                "content": "This project was originated by the late Nick Ing-Simmons and later maintained by Dan Kogai\n<dankogai@cpan.org>.  See AUTHORS for a full list of people involved.  For any questions,\nsend mail to <perl-unicode@perl.org> so that we can all share.\n\nWhile Dan Kogai retains the copyright as a maintainer, credit should go to all those\ninvolved.  See AUTHORS for a list of those who submitted code to the project.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright 2002-2014 Dan Kogai <dankogai@cpan.org>.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms\nas Perl itself.\n\n\n\nperl v5.34.0                                 2022-02-06                                  Encode(3pm)",
                "subsections": []
            }
        }
    }
}