#!perl

use Encode qw/encode decode/;
use Lingua::JA::Romaji;
use DBI;

my %katakana;
my ($spc_dash, $spc_sokuon);
for my $euc (keys %Lingua::JA::Romaji::katakana) {
    my $key = encode('utf8', decode('euc-jp', $euc));
    my $val = $Lingua::JA::Romaji::katakana{$euc};

    if ($val eq '-') {
        $spc_dash = $key;
    } elsif ($val eq '
    $katakana{$key} = $val;
}

#use Data::Dumper; print Dumper(\%katakana);
#exit;

my $dbh = DBI->connect('dbi:mysql:pokedex', 'perl', '');

my @pokemon;
my $sth = $dbh->prepare('SELECT id, name_jp FROM pokemon;');
$sth->execute;
while (my $row = $sth->fetchrow_hashref) {
    $pokemon[ $row->{id} ]{jp} = $row->{name_jp};
}

#$sth = $dbh->prepare('UPDATE pokemon SET evparent=?, evmethod=?, evparam=? WHERE id=?');
for my $i (0 .. $#pokemon) {
#    print kanatoromaji(encode('euc-jp', decode('utf8', $pokemon[$i]{jp}))), "\n";
    my $jp = $pokemon[$i]{jp};
    my $romaji = $jp;
    for my $k (keys %katakana) {
        $romaji =~ s/$k/$katakana{$k}/g;
    }
    print "$romaji\n";
}

