Kakasi(3pm)
π NAME π
okay bestie, welcome to Kakasi(3pm) β a User Contributed Perl Documentation page, and the actual star of the show is Text::Kakasi: the perl frontend to kakasi πβ¨
πΈ SYNOPSIS πΈ
use Text::Kakasi;
# functional
$res = Text::Kakasi::getopt_argv('-JJ', '-c', '-w');
$str = Text::Kakasi::do_kakasi($japanese_text);
# object-oriented
$obj = Text::Kakasi->new('-JJ', '-c', '-w');
$str = $obj->get($japanese_text);
π¦ DESCRIPTION π¦
So this module is literally just an interface to kakasi β that's kanji kana simple inverter π kakasi is a whole set of programs and libraries that does what Japanese input methods do, but in reverse order. You feed it Japanese, and kakasi converts it into the phonetic representation of that same text. It can also tokenize Japanese text, which is lowkey iconic. Want more kakasi lore? Go look at <http://kakasi.namazu.org/> π
Text::Kakasi now serves both functional and object-oriented APIs. The functional APIs are 100% compatible with ver. 1.05, no cap. But if you want to take advantage of the "Perl 5.8 Features", bestie, use the OOP APIs instead π
Also: check out Text::Kakasi::JP for the Japanese version of this document π―π΅
β¨ Functional APIs β¨
Heads up, the Text::Kakasi:: prefix is omitted below π and just so you know, Text::Kakasi does not export these functions by default. You have to import them yourself, like this:
use Text::Kakasi qw/getopt_argv do_kakasi/;
π«Ά $err = getopt_argv($arg1, $arg2, ...)
This initializes kakasi with options β and yeah, the options are literally the same as the kakasi command. Here's the summary, as of kakasi 2.3.4 ποΈ
-a[jE] -j[aE] -g[ajE] -k[ajKH]
-E[aj] -K[ajkH] -H[ajkK] -J[ajkKH]
-i{oldjis,newjis,dec,euc,sjis}
-o{oldjis,newjis,dec,euc,sjis}
-r{hepburn,kunrei} -p -s -f -c"chars"
[jisyo1, jisyo2,,,]
Character Sets:
a: asciij: jisromang: graphick: kana
(j, k defined in jisx0201)
E: kigouK: katakanaH: hiraganaJ: kanji
(E, K, H, J defined in jisx0208)
Options:
-iβ input coding system-oβ output coding system-rβ romaji conversion system-pβ list all readings (with-Joption)-sβ insert separate characters (with-Joption)-fβ furigana mode (with-Joption)-cβ skip chars within jukugo (with-Joption: default TAB CR LF BLANK)-Cβ romaji Capitalize (with-Jaor-Jjoption)-Uβ romaji Upcase (with-Jaor-Jjoption)-uβ callfflush()after 1 character output-wβ wakatigaki mode
Returns 0 on success and nonzero on failure β
And unlike version 1.x, where you had to start the first argument with "kakasi", in version 2.x you can just omit that π« (adding "kakasi" doesn't harm anything, so the compatibility is preserved β everybody wins π)
π $result_str = do_kakasi($str)
Applies kakasi to $str and returns the result. And if anything goes wrong? It returns "undef" π
π close_kanwadic()
Closes dictionary files which are implicitly opened. This one is for backward compatibility only, and fr fr you should never have to use this function today π
π Object-Oriented APIs π
As of 2.0, Text::Kakasi also offers OOP APIs. slay.
π $k = Text::Kakasi->new($args ...)
Constructs an object β¨ When an argument is fed to it, it's the same as "Text::Kakasi->new->set($args ...)".
π
$k->set($args ...)
The OOP interface to "getopt_argv".
my $k = Text::Kakasi->new;
$k->set('-w'); # Text::Kakasi::getopt_argv('-w');
Unlike getopt_argv(), which returns the status, "set" returns the object itself, so you can go full main-character and chain it like this:
my $tokenized = $k->set('-w')->get($raw_japanese);
To get the status of "$k->set", use "$k->error".
See also "Perl 5.8 Features" π§
β $k->error
Returns the status of the last method. That's it, that's the whole vibe check π
π $result = $k->get($raw_japanese);
The OOP interface to "do_kakasi". These two blocks of code are literally equivalent:
# Functional
getopt_argv('-w'); $result = do_kakasi($raw_japanese);
# OOP
$k->set('-w')->get($raw_japanese);
π Perl 5.8 Features π
Perl 5.8 introduced the Encode module, which transcodes various encodings. This module takes advantage of that feature β but to keep backward compatibility with version 1.x, the feature is enabled only when you use the OOP interface (version 1.x only provided functional APIs, so there's the reason, iykyk).
On Perl 5.8 and up, "-iencoding" and "-oencoding" are handled by the Encode module, so you can use encodings Kakasi does not support β like utf8 π¦ In other words:
$result = $k->set(qw/-iutf8 -outf8 -w/)->get($utf8);
Is analogous to:
$euc = encode('eucjp' => $utf8);
getopt_argv('-w');
$tmp = do_kakasi($euc);
$result = decode('eucjp' => $tmp);
When you specify "-outf8", "$k->get" will return the string with the utf8 flag on π©
And if you wanna suppress this whole feature? Just set $Text::Kakasi::HAS_ENCODE to 0, in which case the feature is not used π
βοΈ
π₯ SEE ALSO π₯
kakasi(1)- <http://kakasi.namazu.org/>
Encodeperlunicode
π COPYRIGHT π
(C) 1998, 1999, 2000 NOKUBI Takatsugu <knok@daionet.gr.jp>
(C) 2003 Dan Kogai <dankogai@dan.co.jp>
There is no warranty for this free software, bestie π Anyone can modify and/or redistribute this module under the GNU GENERAL PUBLIC LICENSE. See the COPYING file that's included in the archive for more details π
okay that's the whole page, and before you go β this one's stamped perl v5.42.3, dated 2026-08-19 π«Ά go forth and invert some kanji, you absolute icon πβ¨πΈ
π¦ where this page comes from
- ubuntu stonking: libtext-kakasi-perl 2.04-6build2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms