perl-unicode

Re: Creating a UTF-8 web page

2004-04-08 05:30:07
Octavian Rasnita <orasnita(_at_)fcc(_dot_)ro> writes:
I have tried the following script:

#!/perl/bin/perl -wC

use Encode;

my $text = Encode::decode('latin2', 'mâta');

binmode(STDOUT, ":utf8");

print "Content-Type: text/html; Charset=UTF-8\n\n";
print Encode::encode('utf8', $text);


You have double-encoded that. $text is correctly decoded from Latin2.
So $text is Unicode. Then you encode it is utf8 manually with 
Encode::encode() AND THEN AGAIN as you have told perl with binmode()
that STDOUT is to be encoded as utf8.

Either loose the binmode():

#!/perl/bin/perl -wC
use Encode;
print "Content-Type: text/html; Charset=UTF-8\n\n";
print Encode::encode('utf8', $text);
__END__

or the explict encode:

#!/perl/bin/perl -wC
use Encode;
my $text = Encode::decode('latin2', 'mâta');
binmode(STDOUT, ":utf8");
print "Content-Type: text/html; Charset=UTF-8\n\n";
print $text;
__END__

<Prev in Thread] Current Thread [Next in Thread>