RE: Stripping UTF8 from variables.
by Terrence Martin other posts by this author
Jan 16 2002 8:25PM messages near this date
view in the new Beta List Site
RE: Stripping UTF8 from variables.
|
RE: [ANNOUNCE] XML::SAX::2Simple
> Yes, you're exploiting a bug. The correct way is to use
> utf8::downgrade($var). Of course that's not available in Perl 5.6, it's only
> in 5.7+.
Hmmm well I figured that this was pretty fishy behavior. I have come
across an additional solution to the problem using something called
Unicode::String. Using its conversion features appears to strip the utf8
string off. Does anyone see any issues with this approach?
Cheers,
Terrence
Example
#!/usr/bin/perl
use XML::Simple;
use Devel::Peek;
use Unicode::String qw(utf8 latin1 utf16);
my $config = XMLin("./config.xml");
my $protocol = "$config-> {ssh}->{protocol}";
my $u = utf8($protocol);
my $uconv = $u-> latin1;
print "Protocol = $protocol\n";
Dump $protocol;
print "\n";
print "U = $u\n";
Dump $u;
print "\n";
print "UCONV = $uconv\n";
Dump $uconv;
Sample Output
Protocol = 2
SV = PV(0x8274094) at 0x810447c
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8)
PV = 0x80fe328 "2"\0
CUR = 1
LEN = 2
U = 2
SV = RV(0x8107ce8) at 0x81043c8
REFCNT = 1
FLAGS = (PADBUSY,PADMY,ROK,OVERLOAD)
RV = 0x827e240
SV = PVMG(0x81a81c0) at 0x827e240
REFCNT = 1
FLAGS = (OBJECT,POK,pPOK)
IV = 0
NV = 0
PV = 0x82825d8 "\0002"\0
CUR = 2
LEN = 3
STASH = 0x815aef4 "Unicode::String"
UCONV = 2
SV = PV(0x8274100) at 0x81a598c
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK)
PV = 0x80fe3a8 "2"\0
CUR = 1
LEN = 3
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
http://listserv.ActiveState.com/mailman/listinfo/perl-xml
Thread:
Matt Sergeant
Terrence Martin
|