Skeeve has asked for the wisdom of the Perl Monks concerning the following question:
Hi! I'm a bit puzzled. I'm runnning a file through openssl to decode it. A portion of the output, in which I'm interested, is said to be "in Unicode, padded with 00".
So when I look at it in a hexdump, it reads like this:
00 4d 00 61 00 67 00 6e - 00 65 00 74 00 00 00 00 [.M.a.g.n.e.t....]
There are several strings of bytes which I read from openssl's output. I unpack them into an array. Demo code could be something like this:
$buf="\x00M\x00a\x00g\x00n\x00e\x00t\x00\x00\x00\x00" x 4; my(@unpacked)= unpack "a16" x 4, $buf;
So now I wonder how to convert the bytestrings in @unpacked to proper perl strings which I can print out without the \x00. Additionally I'd like to remove the padded zeroes.
I tried to use decode_utf8 and decode("utf16", ...) on them, but the first one did not seem to have any impact and the latter one fails with (example) "UTF-16:Unrecognised BOM 4d"
Does anyone of you have a hint what I'm doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unicode Puzzle
by ikegami (Patriarch) on Aug 12, 2010 at 21:27 UTC | |
by Skeeve (Parson) on Aug 12, 2010 at 21:49 UTC | |
by aquarium (Curate) on Aug 13, 2010 at 00:27 UTC | |
|
Re: Unicode Puzzle
by moritz (Cardinal) on Aug 13, 2010 at 06:56 UTC |