{
    "mode": "perldoc",
    "parameter": "Jcode",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Jcode/json",
    "generated": "2026-06-15T11:26:51Z",
    "synopsis": "use Jcode;\n#\n# traditional\nJcode::convert(\\$str, $ocode, $icode, \"z\");\n# or OOP!\nprint Jcode->new($str)->h2z->tr($from, $to)->utf8;",
    "sections": {
        "NAME": {
            "content": "Jcode - Japanese Charset Handler\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Jcode;\n#\n# traditional\nJcode::convert(\\$str, $ocode, $icode, \"z\");\n# or OOP!\nprint Jcode->new($str)->h2z->tr($from, $to)->utf8;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "<Japanese document is now available as Jcode::Nihongo. >\n\nJcode.pm supports both object and traditional approach. With object approach, you can go like;\n\n$iso2022jp = Jcode->new($str)->h2z->jis;\n\nWhich is more elegant than:\n\n$iso2022jp = $str;\n&jcode::convert(\\$iso2022jp, 'jis', &jcode::getcode(\\$str), \"z\");\n\nFor those unfamiliar with objects, Jcode.pm still supports \"getcode()\" and \"convert().\"\n\nIf the perl version is 5.8.1, Jcode acts as a wrapper to Encode, the standard charset handler\nmodule for Perl 5.8 or later.\n",
            "subsections": []
        },
        "Methods": {
            "content": "Methods mentioned here all return Jcode object unless otherwise mentioned.\n",
            "subsections": [
                {
                    "name": "Constructors",
                    "content": "$j = Jcode->new($str [, $icode])\nCreates Jcode object $j from $str. Input code is automatically checked unless you explicitly\nset $icode. For available charset, see getcode below.\n\nFor perl 5.8.1 or better, $icode can be *any encoding name* that Encode understands.\n\n$j = Jcode->new($european, 'iso-latin1');\n\nWhen the object is stringified, it returns the EUC-converted string so you can <print $j>\ninstead of <print $j->euc>.\n\nPassing Reference\nInstead of scalar value, You can use reference as\n\nJcode->new(\\$str);\n\nThis saves time a little bit. In exchange of the value of $str being converted. (In a way,\n$str is now \"tied\" to jcode object).\n\n$j->set($str [, $icode])\nSets $j's internal string to $str. Handy when you use Jcode object repeatedly (saves time and\nmemory to create object).\n\n# converts mailbox to SJIS format\nmy $jconv = new Jcode;\n$/ = 00;\nwhile(&lt;&gt;){\nprint $jconv->set(\\$)->mimedecode->sjis;\n}\n\n$j->append($str [, $icode]);\nAppends $str to $j's internal string.\n\n$j = jcode($str [, $icode]);\nshortcut for Jcode->new() so you can go like;\n"
                },
                {
                    "name": "Encoded Strings",
                    "content": "In general, you can retrieve *encoded* string as $j->*encoded*.\n\n$sjis = jcode($str)->sjis\n$euc = $j->euc\n$jis = $j->jis\n$sjis = $j->sjis\n$ucs2 = $j->ucs2\n$utf8 = $j->utf8\nWhat you code is what you get :)\n\n$iso2022jp = $j->iso2022jp\nSame as \"$j->h2z->jis\". Hankaku Kanas are forcibly converted to Zenkaku.\n\nFor perl 5.8.1 and better, you can also use any encoding names and aliases that Encode\nsupports. For example:\n\n$european = $j->isolatin1; # replace '-' with '' for names.\n\nFYI: Encode::Encoder uses similar trick.\n\n$j->fallback($fallback)\nFor perl is 5.8.1 or better, Jcode stores the internal string in UTF-8. Any character that\ndoes not map to *->encoding* are replaced with a '?', which is Encode standard.\n\nmy $unistr = \"\\x{262f}\"; # YIN YANG\nmy $j = jcode($unistr);  # $j->euc is '?'\n\nYou can change this behavior by specifying fallback like Encode. Values are the same as\nEncode. \"Jcode::FBPERLQQ\", \"Jcode::FBXMLCREF\", \"Jcode::FBHTMLCREF\" are aliased to those\nof Encode for convenice.\n\nprint $j->fallback(Jcode::FBPERLQQ)->euc;   # '\\x{262f}'\nprint $j->fallback(Jcode::FBXMLCREF)->euc;  # '&#x262f;'\nprint $j->fallback(Jcode::FBHTMLCREF)->euc; # '&#9775;'\n\nThe global variable $Jcode::FALLBACK stores the default fallback so you can override that by\nassigning the value.\n\n$Jcode::FALLBACK = Jcode::FBPERLQQ; # set default fallback scheme\n\n[@lines =] $jcode->jfold([$width, $newlinestr, $kref])\nfolds lines in jcode string every $width (default: 72) where $width is the number of\n\"halfwidth\" character. Fullwidth Characters are counted as two.\n\nwith a newline string spefied by $newlinestr (default: \"\\n\").\n\nRudimentary kinsoku suppport is now available for Perl 5.8.1 and better.\n\n$length = $jcode->jlength();\nreturns character length properly, rather than byte length.\n"
                },
                {
                    "name": "Methods that use MIME::Base64",
                    "content": "To use methods below, you need MIME::Base64. To install, simply\n\nperl -MCPAN -e 'CPAN::Shell->install(\"MIME::Base64\")'\n\nIf your perl is 5.6 or better, there is no need since MIME::Base64 is bundled.\n\n$mimeheader = $j->mimeencode([$lf, $bpl])\nConverts $str to MIME-Header documented in RFC1522. When $lf is specified, it uses $lf to fold\nline (default: \\n). When $bpl is specified, it uses $bpl for the number of bytes (default: 76;\nthis number must be smaller than 76).\n\nFor Perl 5.8.1 or better, you can also encode MIME Header as:\n\n$mimeheader = $j->MIMEHeader;\n\nIn which case the resulting $mimeheader is MIME-B-encoded UTF-8 whereas \"$j->mimeencode()\"\nreturnes MIME-B-encoded ISO-2022-JP. Most modern MUAs support both.\n\n$j->mimedecode;\nDecodes MIME-Header in Jcode object. For perl 5.8.1 or better, you can also do the same as:\n\nJcode->new($str, 'MIME-Header')\n"
                },
                {
                    "name": "Hankaku vs. Zenkaku",
                    "content": "$j->h2z([$keepdakuten])\nConverts X201 kana (Hankaku) to X208 kana (Zenkaku). When $keepdakuten is set, it leaves\ndakuten as is (That is, \"ka + dakuten\" is left as is instead of being converted to \"ga\")\n\nYou can retrieve the number of matches via $j->nmatch;\n\n$j->z2h\nConverts X208 kana (Zenkaku) to X201 kana (Hankaku).\n\nYou can retrieve the number of matches via $j->nmatch;\n"
                },
                {
                    "name": "Regexp emulators",
                    "content": "To use \"->m()\" and \"->s()\", you need perl 5.8.1 or better.\n\n$j->tr($from, $to, $opt);\nApplies \"tr/$from/$to/\" on Jcode object where $from and $to are EUC-JP strings. On perl 5.8.1\nor better, $from and $to can also be flagged UTF-8 strings.\n\nIf $opt is set, \"tr/$from/$to/$opt\" is applied. $opt must be 'c', 'd' or the combination\nthereof.\n\nYou can retrieve the number of matches via $j->nmatch;\n\nThe following methods are available only for perl 5.8.1 or better.\n\n$j->s($patter, $replace, $opt);\nApplies \"s/$pattern/$replace/$opt\". $pattern and \"replace\" must be in EUC-JP or flagged UTF-8.\n$opt are the same as regexp options. See perlre for regexp options.\n\nLike \"$j->tr()\", \"$j->s()\" returns the object itself so you can nest the operation as follows;\n\n$j->tr(\"a-z\", \"A-Z\")->s(\"foo\", \"bar\");\n\n[@match = ] $j->m($pattern, $opt);\nApplies \"m/$patter/$opt\". Note that this method DOES NOT RETURN AN OBJECT so you can't chain\nthe method like \"$j->s()\".\n"
                },
                {
                    "name": "Instance Variables",
                    "content": "If you need to access instance variables of Jcode object, use access methods below instead of\ndirectly accessing them (That's what OOP is all about)\n\nFYI, Jcode uses a ref to array instead of ref to hash (common way) to optimize speed (Actually\nyou don't have to know as long as you use access methods instead; Once again, that's OOP)\n\n$j->rstr\nReference to the EUC-coded String.\n\n$j->icode\nInput charcode in recent operation.\n\n$j->nmatch\nNumber of matches (Used in $j->tr, etc.)\n"
                }
            ]
        },
        "Subroutines": {
            "content": "($code, [$nmatch]) = getcode($str)\nReturns char code of $str. Return codes are as follows\n\nascii   Ascii (Contains no Japanese Code)\nbinary  Binary (Not Text File)\neuc     EUC-JP\nsjis    SHIFTJIS\njis     JIS (ISO-2022-JP)\nucs2    UCS2 (Raw Unicode)\nutf8    UTF8\n\nWhen array context is used instead of scaler, it also returns how many character codes are\nfound. As mentioned above, $str can be \\$str instead.\n\njcode.pl Users: This function is 100% upper-conpatible with jcode::getcode() -- well, almost;\n\n* When its return value is an array, the order is the opposite;\njcode::getcode() returns $nmatch first.\n\n* jcode::getcode() returns 'undef' when the number of EUC characters\nis equal to that of SJIS.  Jcode::getcode() returns EUC.  for\nJcode.pm there is no in-betweens.\n\nJcode::convert($str, [$ocode, $icode, $opt])\nConverts $str to char code specified by $ocode. When $icode is specified also, it assumes\n$icode for input string instead of the one checked by getcode(). As mentioned above, $str can\nbe \\$str instead.\n\njcode.pl Users: This function is 100% upper-conpatible with jcode::convert() !\n",
            "subsections": []
        },
        "BUGS": {
            "content": "For perl is 5.8.1 or later, Jcode acts as a wrapper to Encode. Meaning Jcode is subject to bugs\ntherein.\n",
            "subsections": []
        },
        "ACKNOWLEDGEMENTS": {
            "content": "This package owes a lot in motivation, design, and code, to the jcode.pl for Perl4 by Kazumasa\nUtashiro <utashiro@iij.ad.jp>.\n\nHiroki Ohzaki <ohzaki@iod.ricoh.co.jp> has helped me polish regexp from the very first stage of\ndevelopment.\n\nJEncode by makamaka@donzoko.net has inspired me to integrate Encode to Jcode. He has also\ncontributed Japanese POD.\n\nAnd folks at Jcode Mailing list <jcode5@ring.gr.jp>. Without them, I couldn't have coded this\nfar.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Encode\n\nJcode::Nihongo\n\n<http://www.iana.org/assignments/character-sets>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 1999-2005 Dan Kogai <dankogai@dan.co.jp>\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "Jcode - Japanese Charset Handler",
    "flags": [],
    "examples": [],
    "see_also": []
}