{
    "mode": "perldoc",
    "parameter": "Encode",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Encode/json",
    "generated": "2026-05-30T18:58:46Z",
    "synopsis": "use Encode qw(decode encode);\n$characters = decode('UTF-8', $octets,     Encode::FBCROAK);\n$octets     = encode('UTF-8', $characters, Encode::FBCROAK);",
    "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\nextensive to fit in one document. This one itself explains the top-level\nAPIs and general topics at a glance. For other topics and more details,\nsee 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\nrest of the system. Perl strings are sequences of *characters*.\n\nThe repertoire of characters that Perl can represent is a superset of\nthose defined by the Unicode Consortium. On most platforms the ordinal\nvalues of a character as returned by \"ord(*S*)\" is the *Unicode\ncodepoint* for that character. The exceptions are platforms where the\nlegacy encoding is some variant of EBCDIC rather than a superset of\nASCII; see perlebcdic.\n\nDuring recent history, data is moved around a computer in 8-bit chunks,\noften called \"bytes\" but also known as \"octets\" in standards documents.\nPerl is widely used to manipulate data of many types: not only strings\nof characters representing human or computer languages, but also\n\"binary\" data, being the machine's representation of numbers, pixels in\nan image, or just about anything.\n\nWhen Perl is processing \"binary data\", the programmer wants Perl to\nprocess \"sequences of bytes\". This is not a problem for Perl: because a\nbyte has 256 possible values, it easily fits in Perl's much larger\n\"logical character\".\n\nThis document mostly explains the *how*. perlunitut and perlunifaq\nexplain the *why*.\n\nTERMINOLOGY\ncharacter\nA character in the range 0 .. 232-1 (or more); what Perl's strings are\nmade of.\n\nbyte\nA character in the range 0..255; a special case of a Perl character.\n\noctet\n8 bits of data, with ordinal values 0..255; term for bytes passed to or\nfrom a non-Perl context, such as a disk file, standard I/O stream,\ndatabase, command-line argument, environment variable, socket etc.\n",
            "subsections": []
        },
        "THE PERL ENCODING API": {
            "content": "",
            "subsections": [
                {
                    "name": "Basic methods",
                    "content": "encode\n$octets  = encode(ENCODING, STRING[, CHECK])\n\nEncodes the scalar value *STRING* from Perl's internal form into\n*ENCODING* and returns a sequence of octets. *ENCODING* can be either a\ncanonical name or an alias. For encoding names and aliases, see\n\"Defining Aliases\". For CHECK, see \"Handling Malformed Data\".\n\nCAVEAT: the input scalar *STRING* might be modified in-place depending\non what is set in CHECK. See \"LEAVESRC\" if you want your inputs to be\nleft unchanged.\n\nFor example, to convert a string from Perl's internal format into\nISO-8859-1, also known as Latin1:\n\n$octets = encode(\"iso-8859-1\", $string);\n\nCAVEAT: When you run \"$octets = encode(\"UTF-8\", $string)\", then $octets\n*might not be equal to* $string. Though both contain the same data, the\nUTF8 flag for $octets is *always* off. When you encode anything, the\nUTF8 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$string = decode(ENCODING, OCTETS[, CHECK])\n\nThis function returns the string that results from decoding the scalar\nvalue *OCTETS*, assumed to be a sequence of octets in *ENCODING*, into\nPerl's internal form. As with encode(), *ENCODING* can be either a\ncanonical 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\non what is set in CHECK. See \"LEAVESRC\" if you want your inputs to be\nleft unchanged.\n\nFor example, to convert ISO-8859-1 data into a string in Perl's internal\nformat:\n\n$string = decode(\"iso-8859-1\", $octets);\n\nCAVEAT: When you run \"$string = decode(\"UTF-8\", $octets)\", then $string\n*might not be equal to* $octets. Though both contain the same data, the\nUTF8 flag for $string is on. See \"The UTF8 flag\" 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[$obj =] findencoding(ENCODING)\n\nReturns the *encoding object* corresponding to *ENCODING*. Returns\n\"undef\" if no matching *ENCODING* is find. The returned object is what\ndoes 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\ninstance, \"name()\" returns the canonical name of the encoding object.\n\nfindencoding(\"latin1\")->name; # iso-8859-1\n\nSee Encode::Encoding for details.\n\nfindmimeencoding\n[$obj =] findmimeencoding(MIMEENCODING)\n\nReturns the *encoding object* corresponding to *MIMEENCODING*. Acts\nsame as \"findencoding()\" but \"mimename()\" of returned object must\nmatch to *MIMEENCODING*. So as opposite of \"findencoding()\" canonical\nnames 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[$length =] fromto($octets, FROMENC, TOENC [, CHECK])\n\nConverts *in-place* data between two encodings. The data in $octets must\nbe encoded as octets and *not* as characters in Perl's internal format.\nFor example, to convert ISO-8859-1 data into Microsoft's CP1250\nencoding:\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\nbe a string constant: it must be a scalar variable.\n\n\"fromto()\" returns the length of the converted string in octets on\nsuccess, and \"undef\" on error.\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,\nbut only #2 turns the UTF8 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\ndeliberately done that way. If you need minute control, use \"decode\"\nfollowed by \"encode\" as follows:\n\n$octets = encode($to, decode($from, $octets, $checkfrom), $checkto);\n\nencodeutf8\n$octets = encodeutf8($string);\n\nWARNING: This function can produce invalid UTF-8! Do not use it for data\nexchange. Unless you want Perl's older \"lax\" mode, prefer \"$octets =\nencode(\"UTF-8\", $string)\".\n\nEquivalent to \"$octets = encode(\"utf8\", $string)\". The characters in\n$string are encoded in Perl's internal format, and the result is\nreturned as a sequence of octets. Because all possible characters in\nPerl have a (loose, not strict) utf8 representation, this function\ncannot fail.\n\ndecodeutf8\n$string = decodeutf8($octets [, CHECK]);\n\nWARNING: This function accepts invalid UTF-8! Do not use it for data\nexchange. Unless you want Perl's older \"lax\" mode, prefer \"$string =\ndecode(\"UTF-8\", $octets [, CHECK])\".\n\nEquivalent to \"$string = decode(\"utf8\", $octets [, CHECK])\". The\nsequence of octets represented by $octets is decoded from (loose, not\nstrict) utf8 into a sequence of logical characters. Because not all\nsequences of octets are valid not strict utf8, it is quite possible for\nthis function to fail. For CHECK, see \"Handling Malformed Data\".\n\nCAVEAT: the input *$octets* might be modified in-place depending on what\nis set in CHECK. See \"LEAVESRC\" if you want your inputs to be left\nunchanged.\n"
                },
                {
                    "name": "Listing available encodings",
                    "content": "use Encode;\n@list = Encode->encodings();\n\nReturns a list of canonical names of available encodings that have\nalready been loaded. To get a list of all available encodings including\nthose 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\nEncode::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*\nmay be either the name of an encoding or an *encoding object*.\n\nBefore you do that, first make sure the alias is nonexistent using\n\"resolvealias()\", which returns the canonical name thereof. For\nexample:\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\nvia \"use Encode qw(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\nIANA Character Set Registry, commonly seen as \"Content-Type: text/plain;\ncharset=*WHATEVER*\". For most cases, the canonical name works, but\nsometimes it does not, most notably with \"utf-8-strict\".\n\nAs of \"Encode\" version 2.21, a new method \"mimename()\" is therefore\nadded.\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"
                }
            ]
        },
        "Encoding via PerlIO": {
            "content": "If your perl supports \"PerlIO\" (which is the default), you can use a\n\"PerlIO\" layer to decode and encode directly via a filehandle. The\nfollowing two examples are fully identical in functionality:\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\nhandle the conversion. In the second, you explicitly translate from one\nencoding to the other.\n\nUnfortunately, it may be that encodings are not \"PerlIO\"-savvy. You can\ncheck to see whether your encoding is supported by \"PerlIO\" by invoking\nthe \"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\n\"PerlIO\"-savvy except for \"hz\" and \"ISO-2022-kr\". For the gory details,\nsee Encode::Encoding and Encode::PerlIO.\n",
            "subsections": []
        },
        "Handling Malformed Data": {
            "content": "The optional *CHECK* argument tells \"Encode\" what to do when\nencountering malformed data. Without *CHECK*, \"Encode::FBDEFAULT\" (==\n0) is assumed.\n\nAs of version 2.12, \"Encode\" supports coderef values for \"CHECK\"; see\nbelow.\n\nNOTE: Not all encodings support this feature. Some encodings ignore the\n*CHECK* argument. For example, Encode::Unicode ignores *CHECK* and it\nalways croaks on error.\n\nList of *CHECK* values\nFBDEFAULT\nI<CHECK> = Encode::FBDEFAULT ( == 0)\n\nIf *CHECK* is 0, encoding and decoding replace any malformed character\nwith a *substitution character*. When you encode, *SUBCHAR* is used.\nWhen you decode, the Unicode REPLACEMENT CHARACTER, code point U+FFFD,\nis used. If the data is supposed to be UTF-8, an optional lexical\nwarning of warning category \"utf8\" is given.\n\nFBCROAK\nI<CHECK> = Encode::FBCROAK ( == 1)\n\nIf *CHECK* is 1, methods immediately die with an error message.\nTherefore, when *CHECK* is 1, you should trap exceptions with \"eval{}\",\nunless you really want to let it \"die\".\n\nFBQUIET\nI<CHECK> = Encode::FBQUIET\n\nIf *CHECK* is set to \"Encode::FBQUIET\", encoding and decoding\nimmediately return the portion of the data that has been processed so\nfar when an error occurs. The data argument is overwritten with\neverything after that point; that is, the unprocessed portion of the\ndata. This is handy when you have to call \"decode\" repeatedly in the\ncase where your source data may contain partial multi-byte character\nsequences, (that is, you are reading with a fixed-width buffer). Here's\nsome 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\nI<CHECK> = Encode::FBWARN\n\nThis is the same as \"FBQUIET\" above, except that instead of being\nsilent on errors, it issues a warning. This is handy for when you are\ndebugging.\n\nCAVEAT: All warnings from Encode module are reported, independently of\npragma warnings settings. If you want to follow settings of lexical\nwarnings configured by pragma warnings then append also check value\n\"ENCODE::ONLYPRAGMAWARNINGS\". This value is available since Encode\nversion 2.99.\n\nFBPERLQQ FBHTMLCREF FBXMLCREF\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\"\nfallback mode.\n\nWhen you decode, \"\\x*HH*\" is inserted for a malformed character, where\n*HH* is the hex representation of the octet that could not be decoded to\nutf8. When you encode, \"\\x{*HHHH*}\" will be inserted, where *HHHH* is\nthe Unicode code point (in any number of hex digits) of the character\nthat cannot be found in the character repertoire of the encoding.\n\nThe HTML/XML character reference modes are about the same. In place of\n\"\\x{*HHHH*}\", HTML uses \"&#*NNN*;\" where *NNN* is a decimal number, and\nXML uses \"&#x*HHHH*;\" where *HHHH* is the hexadecimal number.\n\nIn \"Encode\" 2.10 or later, \"LEAVESRC\" is also implied.\n\nThe bitmask\nThese modes are all actually set via a bitmask. Here is how the\n\"FB*XXX*\" constants are laid out. You can import the \"FB*XXX*\"\nconstants via \"use Encode qw(:fallbacks)\", and you can import the\ngeneric 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\nEncode::LEAVESRC\n\nIf the \"Encode::LEAVESRC\" bit is *not* set but *CHECK* is set, then the\nsource string to encode() or decode() will be overwritten in place. If\nyou're not interested in this, then bitwise-OR it with the bitmask.\n\ncoderef for CHECK\nAs of \"Encode\" 2.12, \"CHECK\" can also be a code reference which takes\nthe ordinal value of the unmapped character as an argument and returns\noctets that represent the fallback character. 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\ncharacters) and takes a list of ordinal values as its arguments. So for\nexample if you wish to decode octets as UTF-8, and use ISO-8859-15 as a\nfallback 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",
            "subsections": []
        },
        "Defining Encodings": {
            "content": "To define a new encoding, use:\n\nuse Encode qw(defineencoding);\ndefineencoding($object, CANONICALNAME [, alias...]);\n\n*CANONICALNAME* will be associated with *$object*. The object should\nprovide the interface described in Encode::Encoding. If more than two\narguments are provided, additional arguments are considered aliases for\n*$object*.\n\nSee Encode::Encoding for details.\n\nThe UTF8 flag\nBefore the introduction of Unicode support in Perl, The \"eq\" operator\njust compared the strings represented by two scalars. Beginning with\nPerl 5.8, \"eq\" compares two strings with simultaneous consideration of\n*the UTF8 flag*. To explain why we made it so, I quote from page 402 of\n*Programming Perl, 3rd ed.*\n\nGoal #1:\nOld byte-oriented programs should not spontaneously break on the old\nbyte-oriented data they used to work on.\n\nGoal #2:\nOld byte-oriented programs should magically start working on the new\ncharacter-oriented data when appropriate.\n\nGoal #3:\nPrograms should run just as fast in the new character-oriented mode as\nin the old byte-oriented mode.\n\nGoal #4:\nPerl should remain one language, rather than forking into a\nbyte-oriented Perl and a character-oriented Perl.\n\nWhen *Programming Perl, 3rd ed.* was written, not even Perl 5.6.0 had\nbeen born yet, many features documented in the book remained\nunimplemented for a long time. Perl 5.8 corrected much of this, and the\nintroduction of the UTF8 flag is one of them. You can think of there\nbeing two fundamentally different kinds of strings and string-operations\nin Perl: one a byte-oriented mode for when the internal UTF8 flag is\noff, and the other a character-oriented mode for when the internal UTF8\nflag is on.\n\nThis UTF8 flag is not visible in Perl scripts, exactly for the same\nreason you cannot (or rather, you *don't have to*) see whether a scalar\ncontains a string, an integer, or a floating-point number. But you can\nstill peek and poke these if you will. See the next section.\n",
            "subsections": [
                {
                    "name": "Messing with Perl's Internals",
                    "content": "The following API uses parts of Perl's internals in the current\nimplementation. As such, they are efficient but may change in a future\nrelease.\n\nisutf8\nisutf8(STRING [, CHECK])\n\n[INTERNAL] Tests whether the UTF8 flag is turned on in the *STRING*. If\n*CHECK* is true, also checks whether *STRING* contains well-formed\nUTF-8. Returns true if successful, false otherwise.\n\nTypically only necessary for debugging and testing. Don't use this flag\nas a marker to distinguish character and binary data, that should be\ndecided for each variable when you write your code.\n\nCAVEAT: If *STRING* has UTF8 flag set, it does NOT mean that *STRING* is\nUTF-8 encoded and vice-versa.\n\nAs of Perl 5.8.1, utf8 also has the \"utf8::isutf8\" function.\n\nutf8on\nutf8on(STRING)\n\n[INTERNAL] Turns the *STRING*'s internal UTF8 flag on. The *STRING* is\n*not* checked for containing only well-formed UTF-8. Do not use this\nunless you *know with absolute certainty* that the STRING holds only\nwell-formed UTF-8. Returns the previous state of the UTF8 flag (so\nplease don't treat the return value as indicating success or failure),\nor \"undef\" if *STRING* is not a string.\n\nNOTE: For security reasons, this function does not work on tainted\nvalues.\n\nutf8off\nutf8off(STRING)\n\n[INTERNAL] Turns the *STRING*'s internal UTF8 flag off. Do not use\nfrivolously. Returns the previous state of the UTF8 flag, or \"undef\" if\n*STRING* is not a string. Do not treat the return value as indicative of\nsuccess or failure, because that isn't what it means: it is only the\nprevious setting.\n\nNOTE: For security reasons, this function does not work on tainted\nvalues.\n\nUTF-8 vs. utf8 vs. UTF8\n....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\nwas first conceived by Ken Thompson when he invented it. However, thanks\nto later revisions to the applicable standards, official UTF-8 is now\nrather stricter than that. For example, its range is much narrower (0 ..\n0x10FFFF to cover only 21 bits instead of 32 or 64 bits) and some\nsequences are not allowed, like those used in surrogate pairs, the 31\nnon-character code points 0xFDD0 .. 0xFDEF, the last two code points in\n*any* plane (0x*XX*FFFE and 0x*XX*FFFF), all non-shortest encodings,\netc.\n\nThe former default in which Perl would always use a loose interpretation\nof UTF-8 has now been 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,\nwhich is conservative and strict and security-conscious, whereas \"utf8\"\nmeans UTF-8 in its former sense, which was liberal and loose and lax.\n\"Encode\" version 2.10 or later thus groks this subtle but critically\nimportant 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\nstores character U+200000, which exceeds UTF-8's allowed range. $s thus\nstores 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\n\"utf-8-strict\". That hyphen between the \"UTF\" and the \"8\" is critical;\nwithout it, \"Encode\" goes \"liberal\" and (perhaps overly-)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\nindicates whether a string is internally encoded as \"utf8\", also without\na hyphen.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "Encode::Encoding, Encode::Supported, Encode::PerlIO, encoding,\nperlebcdic, \"open\" in perlfunc, perlunicode, perluniintro, perlunifaq,\nperlunitut utf8, the Perl Unicode Mailing List\n<http://lists.perl.org/list/perl-unicode.html>\n",
            "subsections": []
        },
        "MAINTAINER": {
            "content": "This project was originated by the late Nick Ing-Simmons and later\nmaintained by Dan Kogai *<dankogai@cpan.org>*. See AUTHORS for a full\nlist of people involved. For any questions, send mail to\n*<perl-unicode@perl.org>* so that we can all share.\n\nWhile Dan Kogai retains the copyright as a maintainer, credit should go\nto all those involved. See AUTHORS for a list of those who submitted\ncode 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\nunder the same terms as Perl itself.\n",
            "subsections": []
        }
    },
    "summary": "Encode - character encodings in Perl",
    "flags": [],
    "examples": [],
    "see_also": []
}