Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

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

Just to compare, I used what already was available to achieve almost the same:

use 5.18.2;
use warnings;
use utf8;
use Encode qw( encode decode );
use Data::Peek;

binmode STDOUT, ":encoding(utf8)";

my @lang = (
    [ Arabic   => "هذا اختبار"                    ],
    [ Chinese  => "這是一個測試"            ],
    [ Greek    => "Αυτό είναι ένα τεστ"         ],
    [ Japanese => "これはテストです"             ],
    [ Russian  => "Это тест"                  ],
    );

my @encodings = (
    "UCS-2",
    "UCS-2BE",
    "UCS-2LE",
    "UTF-7",
    "UTF-8",
    "utf-8-strict",
    "UTF-16",
    "UTF-16BE",
    "UTF-16LE",
    "UTF-32",
    "UTF-32BE",
    "UTF-32LE",
    );

my %hashOutput;
for (@lang) {
    my ($lang, $str) = @$_;
    foreach my $enc (@encodings) {
        printf "--\n%-8s %s\n", $lang, $enc;
        DPeek $str;
        my $bytes = encode ($enc, $str);
        DHexDump $bytes;
        }
    }

=>

-- Arabic UCS-2 PV("\331\207\330\260\330\247 \330\247\330\256\330\252\330\250\330\247\ +330\261"\0) [UTF8 "\x{647}\x{630}\x{627} \x{627}\x{62e}\x{62a}\x{628} +\x{627}\x{631}"] 0000 06 47 06 30 06 27 00 20 06 27 06 2e 06 2a 06 28 .G.0.'. .'...* +.( 0010 06 27 06 31 .'.1 -- Arabic UCS-2BE PV("\331\207\330\260\330\247 \330\247\330\256\330\252\330\250\330\247\ +330\261"\0) [UTF8 "\x{647}\x{630}\x{627} \x{627}\x{62e}\x{62a}\x{628} +\x{627}\x{631}"] 0000 06 47 06 30 06 27 00 20 06 27 06 2e 06 2a 06 28 .G.0.'. .'...* +.( 0010 06 27 06 31 .'.1 -- Arabic UCS-2LE PV("\331\207\330\260\330\247 \330\247\330\256\330\252\330\250\330\247\ +330\261"\0) [UTF8 "\x{647}\x{630}\x{627} \x{627}\x{62e}\x{62a}\x{628} +\x{627}\x{631}"] 0000 47 06 30 06 27 06 20 00 27 06 2e 06 2a 06 28 06 G.0.'. .'...*. +(. 0010 27 06 31 06 '.1. : : : -- Russian UTF-32BE PV("\320\255\321\202\320\276 \321\202\320\265\321\201\321\202"\0) [UTF +8 "\x{42d}\x{442}\x{43e} \x{442}\x{435}\x{441}\x{442}"] 0000 00 00 04 2d 00 00 04 42 00 00 04 3e 00 00 00 20 ...-...B...>.. +. 0010 00 00 04 42 00 00 04 35 00 00 04 41 00 00 04 42 ...B...5...A.. +.B -- Russian UTF-32LE PV("\320\255\321\202\320\276 \321\202\320\265\321\201\321\202"\0) [UTF +8 "\x{42d}\x{442}\x{43e} \x{442}\x{435}\x{441}\x{442}"] 0000 2d 04 00 00 42 04 00 00 3e 04 00 00 20 00 00 00 -...B...>... . +.. 0010 42 04 00 00 35 04 00 00 41 04 00 00 42 04 00 00 B...5...A...B. +..

Enjoy, Have FUN! H.Merijn

In reply to Re: Encoding Decoding on multiple formats RFC by Tux
in thread Encoding Decoding on multiple formats RFC 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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2018-05-21 11:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?