<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># hepburn6.pl
# Reads in all the data first, then uses rules to derive outputs

$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 = &lt;RULESFILE&gt;) {
    chomp($line);
    ($kunrei, $hepburn) = split("\t", $line);
    # Now, place this pair onto the end of the @rules array
    push(@rules, [ $kunrei, $hepburn ]);
}

# Now read in the input forms, and store them so we can learn from them
while ($line = &lt;INFILE&gt;) {
    chomp($line);      
    push (@inputs, $line);    
    
    $check_line = &lt;CHECKFILE&gt;;    
    chomp($check_line);        
    push (@answers, $check_line);        
}

$number_correct = 0;
for ($i = 0; $i &lt;= $#inputs; $i++) {
    # We'll start with the current input, and transform it
    $output = $inputs[$i];        
    for ($r = 0; $r &lt;= $#rules; $r++) {
	$output =~ s/$rules[$r][0]/$rules[$r][1]/g;	
    }
    print "$output"; 
    # Now check answer against the "real" answer in the checkfile
    if ($output eq $answers[$i]) {
	print "\t(correct)\n";	
    } else {
	if ($answers[$i] eq $inputs[$i]) {
	    # We changed something that we shouldn't have
	    print "\t(incorrect - accidentally modified &lt;$inputs[$i]&gt; when we shouldn't have\n";	    
	} else {
	    print "\t(incorrect - need to learn something to change &lt;$inputs[$i]&gt; to &lt;$answers[$i]&gt; \n";	    
	}
    }
}
if ($number_correct == ($#inputs + 1) ) {
    print "\n***Perfect -- all forms accounted for***\n";        	
}
</pre></body></html>