belden has asked for the wisdom of the Perl Monks concerning the following question:
I am parsing the changes to Unihan in Unicode 3.1 Update-1.
I need to generate output in the form \0xE4\0xB8\0xAD
This is the UTF8 value for the Unicode character whose UTF16
value is U+4E2D. (In this case, the Chinese glyph "zhong1", middle.)
My code looks like this:
#!/usr/bin/perl my $utf16 = pack('U',hex(shift)); my $utf8; print("Before echo, length of $utf16: ", length $utf16, "\n"); chomp($utf16 = `echo $utf16`); print("After echo, ength of $utf16: ", length $utf16, "\n"); $utf8 .= sprintf("\\0x%x",ord($_)) foreach(split(/|/,$utf16)); print("$utf8\n"); exit;
My question: how do I replace the `echo` with Perl without
reversing the UTF16 -> UTF8 conversion?
Thanks - Belden
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unicode UTF16 - UTF8 conversion
by belden (Friar) on Sep 11, 2001 at 03:10 UTC |