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" => "خداوند",
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.