First, you're not getting 00, you're getting

Missing argument in sprintf at a.pl line 19, <DATAFILE> line 1. Character: 00

The root of the problem is

my @list = unpack( 'A' x length($string), $string );

"A" trims trailing whitespace, and that includes newlines. You want "a".

my @list = unpack( 'a' x length($string), $string );

or better yet

my @list = unpack( '(a)*', $string );

So,

while (<DATAFILE>) { for my $ch (unpack('(a)*', $_)) { printf "Character:\t%s\t%2.2x\n", $ch, ord($ch)); } }

or

while (<DATAFILE>) { for my $ord (unpack('C*', $_)) { printf "Character:\t%s\t%2.2x\n", chr($ord), $ord); } }

PS - The name of the encoding is UTF-16LE, not UTF16-LE.


In reply to Re: Why aren't spaces from a Unicode file converting to Hexadecimal value 20? by ikegami
in thread Why aren't spaces from a Unicode file converting to Hexadecimal value 20? by Isolder

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.