lars nygaard <[EMAIL PROTECTED]> writes:
> I'm having trouble getting unicode from apache(2.0.48) and perl (5.8.0)
> via LWP(5.76). Here's an illustrative cgi script:
>
> print "Content-type: text/plain; charset=utf-8\n\n";
> print "Det bÃÂr gÃÂ";
>
> And it prints nicely in Mozilla. However, this program:
>
> my $ua = LWP::UserAgent->new;
> my $response = $ua->request(GET 'http://localhost/cgi-bin/test.cgi');
> my $content = $response->content;
> print $content;
>
> prints "Det bÃÂÃÂr gÃÂÃÂ".
You end up with doubly encoded UTF-8 here. What I think is going on
here is that you are running under some UTF-8 locale (default in
Redhat 8 and 9) and perl-5.8.0 will then auto UTF-8 encode strings
on STDOUT. The command 'locale' will print out information about the
current locale.
Upgrading to perl-5.8.2 should actually fix this problem as it does
not go into UTF-8 mode for file handles by default.
Another way to to tell perl that content is utf8(). This can be
achieved with:
use Encode qw(decode_utf8);
....
my $content = decode_utf8($response->content);
print $content;
Yet another way is to turn off the UTF-8 locale. Try setting the LANG
environment variable to 'C' before you run your client program.
Regards,
Gisle