in reply to MultiByte Char handling in perl
It's hard to believe the one statement prints "absolutely fine", while the other prints garbage.
As it is, your code doesn't even compile. There are several typos, there is no Encode::utf8_encode(), you're calling your OO method as a regular function, you haven't specified what exactly MultiByteChar is, etc.
The following code works fine, in the sense that both prints output the same sequence of octets for $[Ee]ncodedString:
#!/usr/bin/perl -w use strict; use Encode; sub changeEncoding { my $stringToEncode = shift; my $EncodedString = Encode::encode("utf8", $stringToEncode); print " $EncodedString "; return $EncodedString; } sub getEncodedString { my $encodedString = changeEncoding("\x{2345}"); print $encodedString ; } getEncodedString();
(though changeEncoding is a misnomer, as it doesn't really change the encoding — rather, it simply encodes a string from Perl's internal (decoded) unicode form)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: MultiByte Char handling in perl
by Anonymous Monk on Mar 07, 2012 at 17:32 UTC | |
by Eliya (Vicar) on Mar 07, 2012 at 17:41 UTC | |
by Anonymous Monk on Mar 07, 2012 at 17:56 UTC |