Tech16 min read

Running jcode.pl 2.13.1.7 on Perl 5.40 After 26 Years and Comparing Every Character Against Encode

IkesanContents

On November 29, 2026, Kazumasa Utashiro released jcode.pl 2.13.1.7.
The announcement post read, “Sorry for keeping you waiting 26 years.”

jcode.pl is a Japanese character encoding conversion library from the Perl 4 era, and Perl itself has included Encode in core for a long time.
Wondering why it was updated now, I checked the release notes and repository—and found that the code wasn’t newly written for this release.

2.13.1.7 is a revision that had been left untouched since April 2011.
The last official release had remained 2.13 from September 2000, which eventually started emitting a defined(%hash) is deprecated warning on newer versions of Perl.
According to the repository’s README, the author had fixed it in his local copy back in 2011, but held off on releasing it because he could not recommend using jcode.pl in the first place.

This release publishes that revision on GitHub alongside past versions as a formal release.
In the release notes, he explains that he is releasing it now “to draw a line under it,” noting that while practical use cases may be rare today, he is leaving it behind for legacy scripts and as a historical record.
No reason is given for why this specific date was chosen.

If it’s for legacy scripts, what actually happens to a script still on 2.13 under modern Perl, and how far does swapping in 2.13.1.7 get you?
I wanted to test this myself, but I have never covered Perl on this blog and haven’t touched Perl in over 10 years.
So I had Claude Code handle everything from designing the test plan to writing the test scripts.

Environment

ItemDetails
MachineGMKtec EVO-X2 (Ubuntu 26.04.1 LTS)
Perl5.40.1 (Ubuntu package)
BaselinesPerl core Encode 3.21, glibc 2.43 iconv
Targets10 versions of jcode.pl (2.0 through 2.13.1.7) from tecolicom/jcode.pl, plus the bundled pkf

To verify whether jcode.pl converts characters accurately, I compared its output byte-for-byte against Encode on the same characters.

What’s in the Repository

According to the release notes, jcode.pl is a library that converts between JIS, EUC, and Shift JIS and auto-detects the input encoding. It started in 1992 as kconv.pl and was distributed for many years via ftp.iij.ad.jp.

That history is preserved directly in the repository’s commit log.
The oldest commit is “revision 1.1” dated February 12, 1992, followed by one commit per revision: 2.13 in September 2000, 2.13.1.1 through 2.13.1.5 in April 2002, and 2.13.1.6 and 2.13.1.7 in April 2011.
The next commit is the creation of the README in October 2017; the last code change was in 2011.
On November 29, 2026, tags and releases were created for nine versions from 2.0 to 2.13.1.7.

The README recommends using the standard Encode library in Perl 5, and asks users to consider retiring jcode.pl rather than patching it to keep it running.
This article is not an evaluation for adopting it in new projects either.

The release notes list the following six changes since 2.13:

RevisionChange
2.13.1.1Fixed jcode::tr ignoring options when reusing cached tables
2.13.1.2Fixed a bug in _jis2sjis
2.13.1.3, 2.13.1.4Fixed documentation typo (&jcode'flush to &jcode'flushcache)
2.13.1.5Changed all octal notations to hexadecimal
2.13.1.6Fixed the code range for the first byte of Shift JIS
2.13.1.7Removed deprecated defined usage on hashes

Loading All 10 Older Versions in Modern Perl

The repository also includes older versions from 2.0 to 2.13.
First, I tried loading all of them with require on Perl 5.40.1 and converting the EUC-encoded string “日本” to Shift JIS.

VersionLinesResult on Perl 5.40.1
2.0617Syntax error (line 291, near do convf()
2.3635Syntax error (line 299, same as above)
2.6664Syntax error (line 328, same as above)
2.8731Can't use 'defined(%hash)' (line 639)
2.9733Same as above (line 641)
2.10733Same as above (line 641)
2.11780Same as above (line 679)
2.13785Same as above (line 684)
2.13.1.7786Loaded and converted accurately (93fa967b)

Only 2.13.1.7 worked.
Notations like 93fa967b in the table represent the converted data as two hexadecimal digits per byte.
In Shift JIS, “日” is 93fa and “本” is 967b.

The do convf(...) call that stops versions 2.0 through 2.6 is a Perl 4-era syntax for invoking subroutines as do name(args).

The defined(%hash) error that stops versions 2.8 through 2.13 is an old way of checking whether a hash is empty. In the Perl 5.22 changelog, this became a fatal error under “defined(@array) and defined(%hash) are now fatal errors.”
According to the same entry, this syntax had been deprecated since 5.6.1 and had emitted deprecation warnings since 5.16.
Because it still ran while it was only a warning, 2.13 effectively stopped loading on Perl 5.22 and later.
The final change in 2.13.1.7 fixes this exact issue.

Checking the diff between 2.13 and 2.13.1.7, only two lines were changed for this:

# 2.13
&init_z2h_euc unless defined %z2h_euc;
&init_z2h_sjis unless defined %z2h_sjis;

# 2.13.1.7
&init_z2h_euc unless %z2h_euc;
&init_z2h_sjis unless %z2h_sjis;

I wanted to compare the conversion behavior between 2.13 and 2.13.1.7, but 2.13 cannot even be loaded on Perl 5.40.1 as-is.
So I created a comparison file by removing defined from just those two lines while leaving everything else from 2.13 intact.
From here on, I will refer to this version as “2.13-modified.”

Reproducing Each Fix Since 2.13

For the changes in the release notes that affect runtime behavior, I crafted one input each that breaks on 2.13-modified and works on 2.13.1.7.

ChangeInput2.13-modified2.13.1.7
jcode::tr cacheOn abcabc, first replace abc with X without options; then run the same mapping with the delete option dXXXXXX (d has no effect)XX
_jis2sjisReturn value of jis2sjis when converting a JIS string of 2 supplementary kanji504
Shift JIS 1st-byte rangeConvert F040 (gaiji area) with sjis2eucffa1f040 (left unconverted)

jcode::tr is a function that adapts Perl’s tr operator for 2-byte characters.
Because building the translation table is expensive, it reuses the previous table if the source and target character sets are identical.
In 2.13, the cache check did not inspect the options, so changing only the options for the same character pair reused the previous table.
The d option deletes source characters that have no corresponding replacement: mapping abc to X turns a into X and deletes b and c.
The expected result is XX, which 2.13.1.7 produces.

The _jis2sjis fix concerns its return value.
The conversion functions are supposed to return the approximate number of bytes converted.
In 2.13, the line in question was $n = length;, and length without an argument returns the length of the special variable $_ rather than the converted string.
In my test, I put an unrelated 50-character string into $_, so it returned 50.
In 2.13.1.7, it is length($s), which returns 4.
The converted string itself was identical in both versions (two geta marks, 81ac81ac).

For the Shift JIS first-byte range, the upper limit treated as the lead byte of a 2-byte character was changed from 0xFC to 0xEF.
0xF0 and above belong to gaiji (user-defined characters) and IBM extensions, which have no corresponding positions in JIS X 0208.
2.13-modified ran these through its conversion formula anyway, producing ffa1, which is not a valid EUC byte sequence.
2.13.1.7 excludes them from conversion, leaving the input untouched.

This range change also affected auto-detection.
I tested passing a single 2-byte EUC character to getcode (encoding auto-detection) across all 8,836 positions of the 94×94 kuten grid.

VersionDetected as eucUndetermined
2.13-modified6,1682,668
2.13.1.77,3641,472

In 2.13-modified, EUC characters whose first byte was 0xF0 or higher could also be parsed as valid Shift JIS, making them ambiguous.
Narrowing the Shift JIS first-byte range resolved those cases in favor of EUC.

The remaining two changes do not alter runtime behavior.
For the octal-to-hexadecimal rewrite, I concatenated the conversion outputs of all 8,836 positions in every direction and verified that the MD5 hashes matched between 2.13-modified and 2.13.1.7.
For the documentation fix, no flush function existed in either version—the actual name was flushcache.

Comparing Every Character Against Encode

JIS X 0208 is a standard defining a character set (the collection of kanji and kana used in Japanese), whereas EUC, Shift JIS, and JIS are encodings (different ways of representing those characters as byte sequences).
cp932, used on Windows, is an extended version of Shift JIS that adds platform-dependent characters.

I compared 2.13.1.7’s conversion output byte-for-byte against Encode.
There are six conversion directions across EUC, Shift JIS, and JIS.

TargetCharacter CountResult
JIS X 02086,8790 mismatches across all 6 directions
Half-width kana630 mismatches across all 6 directions (compared against 7bit-jis for JIS)
JIS X 0212 (supplementary kanji)6,0660 mismatches from EUC to JIS; all become geta marks (81ac) in Shift JIS
1,122 Japanese posts from this blog~210,000 lines, 11.2 MBEvery line matched when encoding was explicitly specified

Because Shift JIS has no slots for supplementary kanji, replacing them with geta marks matches jcode.pl’s documented behavior.

The last row uses all Japanese articles from this blog’s repository concatenated together and filtered to characters representable in both EUC and Shift JIS.
Out of 7,830,136 characters, 2,149 (such as emoji) were dropped.

Two Mistakes in the Test Suite

I didn’t get these clean results on the first try—there were two mistakes in the tests Claude Code wrote.

First, every direction involving JIS failed to match.
The cause was using Encode’s iso-2022-jp-1 as the baseline for strings containing half-width kana.
My local Encode converts half-width kana to full-width kana under iso-2022-jp and iso-2022-jp-1.
jcode.pl, on the other hand, outputs half-width kana as half-width (using the ESC ( I escape sequence).
Switching the baseline to 7bit-jis, which preserves half-width kana, made them match.
Passing the z option to jcode.pl also converts them to full-width, producing the exact same byte sequence as iso-2022-jp.

Second, the JIS X 0208 comparison initially showed 1,883 mismatches.
The test had counted any of the 8,836 EUC positions that “could be decoded by Encode’s euc-jp” as a defined character, which yielded 8,762 positions—far more than the 6,879 characters in JIS X 0208.
My local Encode’s euc-jp includes positions that decode without error but do not round-trip back to the original byte sequence when re-encoded.
Once I changed the test to count only positions that round-trip cleanly on decode and re-encode, the count became 6,879 and mismatches dropped to 0.

The Three Wave Dash Characters and cp932

If you compare against Windows’ cp932 instead of shiftjis, three characters fail to match:

KutenCharacterjcode.pl outputLocal Encode (cp932)
01-33〜 (U+301C)8160Cannot encode
01-34‖ (U+2016)8161Cannot encode
01-61− (U+2212)817cCannot encode

jcode.pl does not go through Unicode; it converts purely by byte arithmetic.
The byte sequence 8160 itself is correct—the mismatch happens because shiftjis and cp932 have different Unicode mapping tables.
In cp932, 8160 maps to U+FF5E (fullwidth tilde).
Although it looks similar to U+301C (wave dash), they are distinct characters in Unicode, so U+301C cannot be encoded.

Platform-Dependent Characters

Shift JIS has Windows extension characters that are not part of JIS X 0208.
I ran the entire range of 2-byte characters defined in cp932 through sjis2euc and counted the results by block.

BlockCount2.13-modified2.13.1.7
NEC special characters (row 13, e.g. ①)83All converted to EUC by formula; round-trips back to Shift JIS intactSame
NEC-selected IBM extensions (starting with ED, EE)374All converted to EUC by formula; round-trips back to Shift JIS intactSame
IBM extensions (starting with FA–FC, e.g. 髙)388All become invalid EUC byte sequences like 13a1262 left unchanged; 126 partially rewritten

Row 13 and NEC-selected IBM extensions simply get shifted mathematically into unused rows of JIS X 0208, so round-tripping within jcode.pl does not corrupt them.
However, decoding those resulting EUC byte sequences with my local Encode’s euc-jp did not recover the original characters: all 374 NEC-selected IBM extensions became different characters, and 10 of the 83 row 13 characters failed to decode.

The 126 IBM extension characters that got partially rewritten were those whose second byte fell in A1–DF.
That range overlaps with 1-byte half-width kana.
Because 2.13.1.7 no longer treats FA–FC as the lead byte of a 2-byte character, the leftover second byte appears to have been converted as half-width kana.
The counts are measured; the explanation is inferred from reading the regular expressions.

Where Auto-Detection Fails

getcode returns whether a given string is JIS, Shift JIS, or EUC.
Because EUC and Shift JIS share overlapping byte ranges, it counts the matched length under both interpretations and returns the longer one.
In the event of a tie, it returns nothing.

To see how often it fails on real prose, I tested it line by line on the blog text from earlier (107,308 lines containing Japanese).

VersionEUC lines undeterminedShift JIS lines undeterminedMisdetected as the opposite encoding
2.13-modified30 lines4 lines0 lines
2.13.1.711 lines4 lines0 lines

Every undetermined line contained three or fewer Japanese characters—things like image alt text with one or two kanji, or short headings like ”### 実写”.
Neither version missed a single line with four or more Japanese characters.

To see the trend on short strings, I generated random strings by character class and ran auto-detection on them (5,000 trials per condition, fixed random seed).
The numbers show the accuracy rate; all misses were undetermined (except for half-width kana).

Character ClassLengthPassed as EUCPassed as Shift JIS
Hiragana, katakana1100.0%100.0%
JIS Level 1 kanji199.5%96.4%
JIS Level 1 kanji2100.0%99.9%
JIS Level 2 kanji157.5%71.4%
JIS Level 2 kanji281.8%91.0%
JIS Level 2 kanji392.7%97.6%
JIS Level 2 kanji598.6%99.8%
JIS Level 2 kanji104,999 / 5,0004,999 / 5,000
JIS Level 2 kanji20100.0%100.0%

As the string gets longer, the chance of it accidentally being valid in both EUC and Shift JIS drops quickly, so accuracy rapidly approaches 100%.

For a single Level 2 kanji in EUC, 2.13-modified scored 46.8%.
Every other row had the same numbers in both versions.

Half-width kana is the one case that gets misdetected rather than left undetermined.
Passing a Shift JIS string of two or more half-width kana returned “euc” in all 5,000 trials.
This is because two bytes of Shift JIS half-width kana can also be read as a single 2-byte EUC character.
This limitation is documented in jcode.pl itself: because half-width kana makes distinguishing EUC from Shift JIS difficult or impossible, auto-detection intentionally ignores it.

Performance

I measured the time to convert the 11.2 MB blog text from EUC to Shift JIS.
Values are the median of three runs. Since the text is Markdown, roughly half of it is ASCII.

MethodSecondsMB/s
iconv command0.045250
Encode (whole file at once)0.12093
Encode (line by line)0.35631
jcode.pl (whole file at once)0.66617
jcode.pl (line by line, with cache)0.74315
jcode.pl (line by line, convert with per-line auto-detection)1.1729.6
jcode.pl (line by line, no cache)2.0515.5

jcode.pl caches previously converted characters in a hash, enabled by default.
Disabling it with nocache made it 2.8x slower.

A pure-Perl implementation using regular expressions and a hash comes within just over 2x of C-backed Encode when converting line by line.
Except for convert with per-line auto-detection, every method produced an identical MD5 hash.
convert differed only because the 11 undetermined lines from the previous section were left unconverted.

Writing and Running an Old-Style CGI Script

Finally, I wrote a typical CGI script from that era to see where modern Perl stops it.
Running it showed that legacy scripts trip less on the encoding conversion itself and more on three other things: library include paths, legacy syntax, and variable scope.

#!/usr/local/bin/perl
require 'jcode.pl';
$line = "日本語の書き込み";      # File saved in EUC
&jcode'convert(*line, 'sjis');
print "Content-type: text/html; charset=Shift_JIS\n\n";
print "<html><body>$line</body></html>\n";

Placing jcode.pl in the same directory and running the script gave the following results:

InvocationResult on Perl 5.40.1
Run as-isExits with Can't locate jcode.pl in @INC
Run with PERL_USE_UNSAFE_INC=1Works
Change to require './jcode.pl';Works
Run with perl -I.Works

@INC is the list of directories Perl searches for libraries, which used to include the current directory.
Starting in Perl 5.26, the current directory (.) was removed from @INC by default for security reasons.
Setting the environment variable PERL_USE_UNSAFE_INC=1, documented on the same changelog page, puts . back into @INC, though it is noted as a temporary escape hatch slated for removal in a future Perl release.

Even when the script ran, the following line was printed to stderr despite warnings not being enabled:

Old package separator "'" deprecated at bbs.cgi line 5.

The ' in &jcode'convert is Perl 4’s apostrophe package separator, equivalent to modern jcode::convert.
This syntax was deprecated in Perl 5.38 and scheduled for removal in 5.42.
According to the Perl 5.42 changelog, it was indeed removed in development release 5.41.3 as planned, but after discussion it was restored as enabled by default.
In 5.42, it is controlled via the apostrophe_as_package_separator feature.
Since I only have 5.40.1 installed locally, I haven’t verified 5.42’s behavior firsthand.

Because jcode.pl itself defines its functions inside a package declaration, no warnings came from the library itself—only from the calling script.

There is one more gotcha when trying to modernize the script.
If you declare the variable with my while keeping the old *line argument style, it returns the unconverted string with no error and no warning.

Calling styleResulting bytes
my $line passed to &jcode'convert(*line, 'sjis')c6fccbdcb8ec (still EUC)
my $line passed to jcode::convert(\$line, 'sjis')93fa967b8cea (Shift JIS)

*line is an old notation called a “typeglob,” which refers collectively to package variables of that name accessible across the program.
A variable declared with my $line, however, is a “lexical variable” scoped only to its block, completely separate from package variables.
As a result, passing a my variable via *line hands jcode.pl an unrelated empty variable.
In Perl 5 and later, passing a reference to the variable itself (\$line) is the safe approach, and jcode.pl’s own documentation recommends it.

The bundled pkf is a character-encoding conversion command built on jcode.pl.
It also calls require 'jcode.pl'; internally, so running it as-is hits the same @INC error.
Running perl -I. pkf -s converted an EUC file to Shift JIS, and -c printed the encoding name (euc), with six deprecation warnings on stderr.

All six test scripts used in this experiment were written by Claude Code; I didn’t write a single line of Perl myself.
The full set of scripts is available in LiltingChannelLabo.