bpa has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl #$test = "\x{05D0}\x{20AC}"; #$test = "\xd7\x90\xe2\x82\xac"; #$test = "\x05\xD0\x20\xAC"; $test = '®'; #$test = "\x{c2ae}"; $unpacked = unpack('H*',$test); print("string: $test\n"); print("unpacked: $unpacked\n"); print("char length: " . length($test) . "\n"); print("byte length: " . getByteLength($test) . "\n"); sub getByteLength { my ($string) = @_; use Encode qw(encode decode); $binaryString = encode('UTF-8', $string); my $byteLength = length($binaryString); return $byteLength; }
string: ® unpacked: c2ae char length: 2 byte length: 4
$test = "\x{05D0}\x{20AC}";
$test = "\x05\xD0\x20\xAC"
$test = "\xd7\x90\xe2\x82\xac";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: UTF-8 representation question
by ikegami (Patriarch) on Sep 02, 2008 at 22:50 UTC | |
by bpa (Novice) on Sep 04, 2008 at 03:22 UTC | |
by ikegami (Patriarch) on Sep 04, 2008 at 05:38 UTC | |
|
Re: UTF-8 representation question
by Anonymous Monk on Sep 03, 2008 at 03:05 UTC |