# hepburn4.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"; # Construct an array of arrays. # The syntax is unintuitive; the square brackets take the list inside of them, # bundle them up, and store them somewhere. The first item in the @rules array, # then, is a reminder of where to go to find those values. @rules = ( ["hu", "fu"], ["ty", "ch"], ["sy", "sh"], ["zy", "j"], ["ti", "chi"], ["si", "shi"], ["zi", "ji"], ["tu", "tsu"], ); 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"; } } }