#!/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 translated.\n";; open (FILEOUT, ">$fileout") or die "Can't open output file.\n";; ## Go through each line and replace while ($linein = ) { 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_LatinAmerican|es_MX") { $spanishword = $arrayin[1]; } if (exists $arrayin[0] && $arrayin[0] eq "Spanish_LatinAmerican|es_MX") { $langhash{$spanishword} = $englishword; } } ## while (($spanishword, $englishword) = each %langhash){ ##Print entire hash tableS ## print "$englishword => $spanishword\n"; ## } close(FILEIN2); close(FILEOUT); ##while (($spanishword, $englishword) = each %langhash){ ##Print entire hash tableS ## print "$englishword => $spanishword\n"; ## print "$langhash{$spanishword}\n"; ## } $spanishword = &trim (" Espere para verificar el estado del operador. "); if (exists $langhash{$spanishword}){ print "$langhash{$spanishword}\n"; } else { print "No match\n"; } sub trim { for (my $s = $_[0]) { s/^\s+//; s/\s+$//; return $_; } }