# hepburn5.pl # Converts Japanese text in "official" Monbushoo (Kunrei-shiki) romanization # to more common "Hepburn"-style romanization # A list of differences can be found at: # http://en.wikipedia.org/wiki/Romaji $input_file = "Japanese-ToConvert.txt"; open (INFILE, $input_file) or die "Warning! Can't open input file: $!\n"; $check_file = "Japanese-Converted.txt"; open (CHECKFILE, $check_file) or die "Warning! Can't open check file: $!\n"; $rules_file = "JapaneseRules.txt"; open (RULESFILE, $rules_file) or die "Warning! Can't open rule file: $!\n"; # Read in the file and store each line in the rules array of arrays while ($line = ) { chomp($line); ($kunrei, $hepburn) = split("\t", $line); # Now, place this pair onto the end of the @rules array push(@rules, [ $kunrei, $hepburn ]); } while ($line = ) { chomp($line); $original = $line; for ($i = 0; $i <= $#rules; $i++) { $line =~ s/$rules[$i][0]/$rules[$i][1]/g; } print "$line"; # Now check answer against the "real" answer in the checkfile $check_line = ; chomp($check_line); if ($line eq $check_line) { print "\t(correct)\n"; } else { if ($check_line eq $original) { # We changed something that we shouldn't have print "\t(incorrect - accidentally modified <$original> when we shouldn't have\n"; } else { print "\t(incorrect - need to learn something to change <$original> to <$check_line> \n"; } } }