use warnings; #!/usr/bin/perl ##Objective is to translate Spanish Prompts to English Prompts ## FIL filename for translation $fileone="COM_211_RAD_07A_ES_MX.FIL"; ## LAN filename for translation $filetwo="VoiceLink only Soriana.lan"; ## Debug file to be translated $filetotranslate = "test.txt"; ## English to Spanish translations file $fileout="out.txt"; $fileout2="out2.txt"; ## Debug file with translated from Spanish to English $fileout3="debug.txt"; ## Open the lan file to read in the English and Spanish words ##open (FILEIN, $fileone) or die "Can't open first file.\n";; ## Read in each line and create a hash table ##while ($linein = <FILEIN>) { ## chomp $linein; ## @arrayin = split /\|/, $linein; ##creates an array wit +h split function using | as separator ## $englishword = $arrayin[0]; ## $spanishword = $arrayin[1]; ## print "$englishword -> $spanishword\n"; ## $langhash{$spanishword} = $englishword; ## print "$langhash{$spanishword}\n"; ##} ##close(FINEIN); ## Open Lan file to read in the English and Spanish words open (FILEIN2, $filetwo) or die "Can't open debug file to be translat +ed.\n";; open (FILEOUT, ">$fileout2") or die "Can't open output file.\n";; ## Go through each line and replace while ($linein = <FILEIN2>) { chomp $linein; @arrayin = split /:/, $linein; ##creates an array with + split function using : as separator if ($arrayin[0] eq "Default") { $englishword = $arrayin[1]; } if ($arrayin[0] eq "Spanish_LatinAmerican|es_MX") { $spanishword = $arrayin[1]; } if ($arrayin[0] eq "Spanish_LatinAmerican|es_MX") { $langhash{$spanishword} = $englishword; ## print FILEOUT "$englishword -> $spanishword\n"; }} while (($spanishword, $englishword) = each %langhash){ ##Prin +t entire hash table print FILEOUT "$spanishword=>$englishword\n"; } close(FILEIN2); close(FILEOUT); ## Open debug file to convert from English to Spanish open (FILEIN3, $filetotranslate) or die "Can't open debug file.\n"; open (FILEOUT3, ">$fileout3") or die "Can't open output file.\n"; ## Go through each line and replace while ($linein3 = <FILEIN3>) { if ($linein3 =~ s/##\s*([^#]+?)\s*##/##$langhash{$1}##/){ print FILEOUT3 "$linein3"; } else { print FILEOUT3 "$linein3"; }}
In reply to Re^2: substitution not working correctly
by qnguyen
in thread substitution not working correctly
by qnguyen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |