JayBonci has asked for the wisdom of the Perl Monks concerning the following question:
õ become &3245;I figure the best way to do that would be to pack the string. Take this code snippet for example:
Under perl5.6.x, I receive:#!/usr/bin/perl -w use strict; my $foo = "abcdefghijklmnopqrstuvwxyz[]ö÷"; my $outstr = ""; foreach my $char(split("",$foo)) { if((my $num = unpack("U", $char)) < 125) { $outstr.= $char; } else { $outstr.="\&\#$num\;"; } } print $outstr;
jaybonci@willowisp:~/perl$ ./pack.pl Malformed UTF-8 character (1 byte, need 4) in unpack at ./pack.pl line 9. Malformed UTF-8 character (1 byte, need 4) in unpack at ./pack.pl line 9.However, under perl 5.8, I recieve the proper output:
abcdefghijklmnopqrstuvwxyz[]ö÷
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problems with packing upper ASCII - differences across perl versions
by John M. Dlugosz (Monsignor) on Nov 29, 2002 at 17:40 UTC | |
Re: Problems with packing upper ASCII - differences across perl versions
by Monky Python (Scribe) on Nov 29, 2002 at 12:26 UTC | |
by JayBonci (Curate) on Nov 29, 2002 at 12:47 UTC |