I am having a problem with using spanish characters in my hashes. If I use a spanish word for a key, ex. dígito verificador incorrecto., it will not return the hash value. I know the hash key and value exist in my hash table. Does anyone have any suggestions?
#!/usr/bin/perl use warnings; use strict; ## LAN filename for translation my $filetwo="test2.txt"; ## Translated debug file my $fileout="out.txt"; my $linein; my $englishword; my $spanishword; my %langhash; my @arrayin; ## 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, ">$fileout") 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 (exists $arrayin[0] && $arrayin[0] eq "Default") { $englishword = $arrayin[1]; } if (exists $arrayin[0] && $arrayin[0] eq "Spanish_LatinAmerica +n|es_MX") { $spanishword = $arrayin[1]; } if (exists $arrayin[0] && $arrayin[0] eq "Spanish_LatinAmerica +n|es_MX") { $langhash{$spanishword} = $englishword; } } ## while (($spanishword, $englishword) = each %langhash){ ##Pr +int entire hash tableS ## print "$englishword => $spanishword\n"; ## } close(FILEIN2); close(FILEOUT); ##while (($spanishword, $englishword) = each %langhash){ ##Print en +tire hash tableS ## print "$englishword => $spanishword\n"; ## print "$langhash{$spanishword}\n"; ## } if (exists $langhash{'dígito verificador incorrecto.'}){ print "$langhash{'dígito verificador incorrecto.'}\n"; } else { print "No match\n"; }
Test2.txt contents:
Comment:No Translation Needed Default:digit incorrect. Translate: FALSE Spanish_LatinAmerican|es_MX:dígito verificador incorrecto. Comment: This message is spoken to an operator when the "release licen +se" voice command is used. The message confirms to the operator that +the license was released. Default:Say ready. Translate: FALSE Spanish_LatinAmerican|es_MX:listo. Comment: This message is spoken to an operator when the "release licen +se" voice command is used. The message confirms to the operator that +the license was released. Default:Reverse Translate: FALSE Spanish_LatinAmerican|es_MX:Forward

In reply to Hash not working correctly with spanish words by qnguyen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.