{
    "mode": "perldoc",
    "parameter": "Encode",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Encode/json",
    "generated": "2026-06-13T14:46:16Z",
    "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 extensive to fit in one\ndocument. This one itself explains the top-level APIs and general topics at a glance. For other\ntopics 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. Perl\nstrings 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\" but\nalso known as \"octets\" in standards documents. Perl is widely used to manipulate data of many\ntypes: 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 about\nanything.\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 fits\nin Perl's much larger \"logical character\".\n\nThis document mostly explains the *how*. perlunitut and perlunifaq explain the *why*.\n\nTERMINOLOGY\ncharacter\nA character in the range 0 .. 232-1 (or more); what Perl's strings are made 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 from a non-Perl context,\nsuch as a disk file, standard I/O stream, database, command-line argument, environment variable,\nsocket 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 *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 you\nencode anything, the UTF8 flag on the result is always off, even when it contains a completely\nvalid 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 value *OCTETS*, assumed\nto be a sequence of octets in *ENCODING*, into Perl's internal form. As with encode(),\n*ENCODING* 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 flag\"\nbelow.\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 \"undef\" if no matching\n*ENCODING* 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[$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[$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 constant:\nit 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 UTF8\nflag 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 you\nneed minute control, use \"decode\" followed 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 exchange. Unless you\nwant 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 possible\ncharacters in Perl have a (loose, not strict) utf8 representation, this function cannot fail.\n\ndecodeutf8\n$string = decodeutf8($octets [, CHECK]);\n\nWARNING: This function accepts invalid UTF-8! Do not use it for data exchange. Unless you want\nPerl's older \"lax\" mode, prefer \"$string = decode(\"UTF-8\", $octets [, CHECK])\".\n\nEquivalent to \"$string = decode(\"utf8\", $octets [, CHECK])\". The sequence of octets represented\nby $octets is decoded from (loose, not strict) utf8 into a sequence of logical characters.\nBecause not all sequences of octets are valid not strict utf8, it is quite possible for this\nfunction 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 get a\nlist 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\nof an 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"
                },
                {
                    "name": "qw",
                    "content": "See 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"
                }
            ]
        },
        "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 the\nsecond, 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\" and\n\"ISO-2022-kr\". For the gory details, see Encode::Encoding and Encode::PerlIO.\n",
            "subsections": []
        },
        "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\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 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. Therefore, when *CHECK* is 1,\nyou should trap exceptions with \"eval{}\", unless you really want to let it \"die\".\n\nFBQUIET\nI<CHECK> = Encode::FBQUIET\n\nIf *CHECK* is set to \"Encode::FBQUIET\", encoding and decoding immediately return the portion of\nthe data that has been processed so far when an error occurs. The data argument is overwritten\nwith everything after that point; that is, the unprocessed portion of the data. This is handy\nwhen you have to call \"decode\" repeatedly in the case where your source data may contain partial\nmulti-byte character sequences, (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 silent on errors, it issues a\nwarning. This is handy for when you are debugging.\n\nCAVEAT: All warnings from Encode module are reported, independently of pragma warnings settings.\nIf you want to follow settings of lexical warnings configured by pragma warnings then append\nalso check value \"ENCODE::ONLYPRAGMAWARNINGS\". This value is available since Encode version\n2.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\" \"==\" \"Encode::FBPERLQQ\"\nputs \"encode\" and \"decode\" into \"perlqq\" fallback mode.\n\nWhen you decode, \"\\x*HH*\" 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 \"&#x*HHHH*;\" where *HHHH* is the\nhexadecimal 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 \"FB*XXX*\" constants are laid\nout. You can import the \"FB*XXX*\" constants via \"use Encode qw(:fallbacks)\", and you can import\nthe 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\nEncode::LEAVESRC\n\nIf the \"Encode::LEAVESRC\" bit is *not* set but *CHECK* is set, then the source string to",
            "subsections": [
                {
                    "name": "encode",
                    "content": "bitwise-OR it with the bitmask.\n\ncoderef for CHECK\nAs of \"Encode\" 2.12, \"CHECK\" can also be a code reference which takes the ordinal value of the\nunmapped character as an argument and returns octets that represent the fallback character. For\ninstance:\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 use\nISO-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"
                }
            ]
        },
        "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 provide the interface\ndescribed in Encode::Encoding. If more than two arguments are provided, additional arguments are\nconsidered aliases for *$object*.\n\nSee Encode::Encoding for details.\n\nThe UTF8 flag\nBefore the introduction of Unicode support in Perl, The \"eq\" operator just compared the strings\nrepresented by two scalars. Beginning with Perl 5.8, \"eq\" compares two strings with simultaneous\nconsideration of *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 byte-oriented data they\nused to work on.\n\nGoal #2:\nOld byte-oriented programs should magically start working on the new character-oriented data\nwhen appropriate.\n\nGoal #3:\nPrograms should run just as fast in the new character-oriented mode as in the old\nbyte-oriented 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 much\nof this, and the introduction of the UTF8 flag is one of them. You can think of there being two\nfundamentally different kinds of strings and string-operations in Perl: one a byte-oriented mode\nfor when the internal UTF8 flag is off, and the other a character-oriented mode for when the\ninternal 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\nfloating-point number. But you can still 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 implementation. As such, they\nare efficient but may change in a future release.\n\nisutf8\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 otherwise.\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 write\nyour code.\n\nCAVEAT: If *STRING* has UTF8 flag set, it does NOT mean that *STRING* is UTF-8 encoded and\nvice-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 *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 (so\nplease don't treat the return value as indicating success or failure), or \"undef\" if *STRING* is\nnot a string.\n\nNOTE: For security reasons, this function does not work on tainted values.\n\nutf8off\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 return\nvalue as indicative of success 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 values.\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 was first conceived by\nKen 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 are\nnot allowed, like those used in surrogate pairs, the 31 non-character code points 0xFDD0 ..\n0xFDEF, the last two code points in *any* plane (0x*XX*FFFE and 0x*XX*FFFF), all non-shortest\nencodings, etc.\n\nThe former default in which Perl would always use a loose interpretation of UTF-8 has now been\noverruled:\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 and\nstrict and security-conscious, whereas \"utf8\" means UTF-8 in its former sense, which was liberal\nand loose and lax. \"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 stores character U+200000,\nwhich 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 is\ninternally encoded as \"utf8\", also without a hyphen.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "Encode::Encoding, Encode::Supported, Encode::PerlIO, encoding, perlebcdic, \"open\" in perlfunc,\nperlunicode, perluniintro, perlunifaq, perlunitut 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 maintained by Dan Kogai\n*<dankogai@cpan.org>*. See AUTHORS for a full list of people involved. For any questions, send\nmail 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 involved.\nSee 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 as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "Encode - character encodings in Perl",
    "flags": [],
    "examples": [],
    "see_also": []
}