Print a list of numbers in Japanese kanji, hiragana and romaji

This Perl program prints a list of Japanese numbers from one to a thousand. It requires the CPAN modules Lingua::JA::Numbers and Lingua::JA::Moji to be installed.

#!/usr/bin/env perl
use warnings;
use strict;
use Lingua::JA::Numbers;
use Lingua::JA::Moji 'kana2romaji';

# The following line sets the output encoding to UTF-8.

binmode STDOUT, ":encoding(utf8)";

# To get output in EUC-JP, uncomment (remove the leading #) the
# following line, and comment the one above.

#binmode STDOUT, ":encoding(EUC-JP)";

# The following parameters control the start and the end of the
# generated Japanese output numbers.


my $first = 1;
my $last = 1000;

for my $number ($first..$last) {
    my $kanji = num2ja ($number, {style => 'kanji'});
    my $kana = num2ja ($number, {style => 'hiragana'});
    my $romaji = kana2romaji ($kana, {style => 'hepburn'});
    # Adjust the following format to produce desired output.
    print <<EOF;
$number
$kanji
$kana
$romaji

EOF
}

(download)


Copyright © Ben Bullock 2009-2019. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer