I am trying to work with English and Dari - starting with a simple 1-1 translation.
It goes from English to Dari ok (except everything is printed backwards, L->R), but nothing is printed when Dari is input. Part of the problem is the backwards issue, w/Dari in STDIN (& STDOUT) it comes out L->R - I don't know how to address this so it will match the keys in %dari2english
(ex: خداوند بود خردمند should be translated as "God was wise" but nothing is printed; When going from E->D God was wise, you get the right words in the right order, but with the letters in the words going L->R (I can't replicate it here))
Thanks for any help.
#!/usr/bin/perl use utf8; binmode STDOUT, ":utf8"; %english2dari = ( "wise" => "خردمند", "was" => "بود", "God" => "خداوند"); %dari2english = reverse %english2dari; do{ print "Give a sentence in Dari or English:\n"; chomp ($line = <>); if ($line =~ /\w/){ $line =~ s/^\s*//; $line =~ s/\s*$//; @words = split /\s+/, $line; @words = reverse @words; #word order R-> L but problem remains w/letters L->R foreach $word(@words){ if (exists ($english2dari{$word})){ $dariword = reverse $english2dari{$word} =~ m/\X/g; #should (dnw)reverse how Dari words print, so it's R->L print " $dariword " ; } elsif (exists ($dari2english{$word})) { print " $word "; #this doesn't seem to work at all } else { print " $word "; #unknown - doesn't work either } } } print "\n"; }
In my system, %english2dari displays the characters correctly:
"wise" => "خردمند", "was" => "بود", "God" => "خداوند",
In reply to reversed hash doesn't identify keys by holly_71
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |