Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

G'day thanos1983,

You can get the code points, without firing up the regex engine, like this:

$ perl -Mutf8 -C -E 'my $x = "ﻟﻠﺒﻴﻊ"; say sprintf "%x", ord substr $x, $_, 1 for 0 .. length($x) - 1'
fedf
fee0
fe92
fef4
feca

I don't speak, read or write Arabic; however, checking against Unicode's (PDF) code chart "Arabic Presentation Forms-B", these certainly appear correct.

You asked about getting a "0x" prefix. You can do that with sprintf by changing "%x" to "%#x".

$ perl -Mutf8 -C -E 'my $x = "ﻟﻠﺒﻴﻊ"; say sprintf "%#x", ord substr $x, $_, 1 for 0 .. length($x) - 1'
0xfedf
0xfee0
0xfe92
0xfef4
0xfeca

I don't know anything about UCS, so I might be missing something here. The output you show under "UCS-2", is just the code points, from my first one-liner, as pairs of hex digits (which, obviously, you could get with substr - still not needing a regex).

I accidentally generated what you show as "UTF-8" output, when I initially wrote that first one-liner, because I forgot to add the utf8 pragma.

$ perl -C -E 'my $x = "ﻟﻠﺒﻴﻊ"; say sprintf "%x", ord substr $x, $_, 1 for 0 .. length($x) - 1'
ef
bb
9f
ef
bb
a0
ef
ba
92
ef
bb
b4
ef
bb
8a

Anyway, knowing neither Arabic nor UCS, I don't want to draw any inferences from that output. It might, however, provide you with some insights.

The second part of your title was "... Hex to Arabic". Just printing the hex output I first got, gives me the original Arabic string.

$ perl -C -E 'say "\x{fedf}\x{fee0}\x{fe92}\x{fef4}\x{feca}"'
ﻟﻠﺒﻴﻊ

P.S. I'm using 5.26.0.

— Ken


In reply to Re: Arabic to Hex and Hex to Arabic by kcott
in thread Arabic to Hex and Hex to Arabic by thanos1983

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

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

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (9)
    As of 2018-09-21 17:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Eventually, "covfefe" will come to mean:













      Results (188 votes). Check out past polls.

      Notices?
      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!