# 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 = ) { 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 = ) { chomp($line); push (@inputs, $line); $check_line = ; chomp($check_line); push (@answers, $check_line); } $number_correct = 0; for ($i = 0; $i <= $#inputs; $i++) { # We'll start with the current input, and transform it $output = $inputs[$i]; for ($r = 0; $r <= $#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 <$inputs[$i]> when we shouldn't have\n"; } else { print "\t(incorrect - need to learn something to change <$inputs[$i]> to <$answers[$i]> \n"; } } } if ($number_correct == ($#inputs + 1) ) { print "\n***Perfect -- all forms accounted for***\n"; }