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" => "&#1582;&#1585;&#1583;&#1605;&#1606;&#1583;", "was" => "&#1576;&#1608;&#1583;", "God" => "&#1582;&#1583;&#1575;&#1608;&#1606;&#1583;"); %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

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.