in reply to Re^6: substitution not working correctly
in thread substitution not working correctly

For some odd reason, I get "Can't open debug file to be translated."...

Replies are listed 'Best First'.
Re^8: substitution not working correctly
by qnguyen (Acolyte) on Sep 24, 2007 at 17:23 UTC
    Im not sure why are are getting that error, but I dont get it. If I set the hash value as seen below $langhash{"dígito verificador incorrecto."} = "digit incorrect.";. I get the desired response. Is there a problem with how Im creating my hash table and using it when I translate my file?
    #!/usr/bin/perl use warnings; ##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="test2.txt"; ## Debug file to be translated $filetotranslate = "test.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 (FILEOUT2, ">$fileout2") or die "Can't open output file.\n";; 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; $langhash{"dígito verificador incorrecto."} = "digit incorrect +."; ## print FILEOUT2 "$langhash{$spanishword}\n"; }} ## while (($spanishword, $englishword) = each %langhash){ ##Pr +int entire hash table ## print FILEOUT2 "$spanishword=>$englishword\n"; ## } close(FILEIN2); close(FILEOUT2); ## 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*##/){ if (exists ($langhash{$1})){ $linein3=~ s/##\s*([^#]+?)\s*##/##$langhash{$1}##/; print FILEOUT3 "$linein3"; } else { $linein3=~ s/##\s*([^#]+?)\s*##/##$1##/; print FILEOUT3 "$linein3"; }}} close(FILEIN3); close(FILEOUT3);
      I believe I found the problem. It seems as though Perl does not like the spanish characters when I am using it in a hash. For instance: print "$langhash{'dígito verificador incorrecto.'}\n";. It looks like I will need to do some research.