Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-29 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found