The Unicode range for Arabic is U+0600 - U+06FF, and the first 128 elements of this range is essentially equivalent to the various non-Unicode Arabic code pages (iso-8859-6 and cp1256, which differ from each other only in what they do with the "non-Arabic" code points -- i.e. the gaps around the actual Arabic letters).

In general, if the Arabic data is in a single-byte encoding (i.e. not in Unicode), then your task is simply to convert from that to Unicode, and all you need to worry about is which non-unicode code page to use: iso-8859-6, or cp1256. The choice will only make a difference if the source data is actually cp1256, and it uses some of the non-ISO code points that M$ is so fond of (e.g. "smart quotes", "special hyphen", possibly even some accented Latin letters like é): those will show up as "\x{fffd}" when you treat the input as iso-8859-6 when converting to unicode.

So the best strategy is: assume the data is really cp1256 (because this will cause no harm to iso-8859-6 data) -- a simple one-liner will do:

perl -e 'open(I,q/<:encoding(cp1256)/,shift);binmode STDOUT,q/:utf8/;p +rint <I>' ifile > ofile
(It's very unlikely that the source data involves the old and all-too-clever MacArabic encoding, but if it did, there is a module for handling that as well: Lingua::AR::MacArabic. This encoding stands out in having two versions of various bracketing characters, left-to-right vs right-to-left. Don't worry about it.)

(updated to shorten the one-liner a bit (then a bit more), and to put a real accented letter in the second paragraph)


In reply to Re: Encoding problem by graff
in thread Encoding problem by grscott

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.