Closed MaxPerl closed 8 years ago
$body
is not bytes when you put utf8
pragma. You need to make $body
be bytes as below.
#! /usr/bin/env perl
use strict;
use Plack::Request;
use utf8;
my $app = sub {
my $env = shift;
my $request = Plack::Request->new($env);
my $body = "<head><meta charset=\"utf-8\"</head><p>Höölölüßßß</p>";
return [
'200',
[ 'Content-Type' => 'text/html', 'charset' => 'utf-8' ],
[ Encode::encode_utf8($body) ],
];
};
Dear syohex,
thank you very very much for your answer. Now finally I see what I did wrong. I must write $body=Encode::encode('utf8)
instead of only Encode::encode('utf8)
.
Sometimes I am really blockhead. Sorry for disturbing and thank you all for your great work!!!
Hello all, I noticed a curious problem: I know that I need to send output as a bytestring. Therefore the following worked as expected: `
! /usr/bin/env perl
use strict; use Plack::Request;
my $app = sub { my $env = shift;
}; `
But if I add the pragma "use utf8;" with the same code, encoding is broken.
Anyone an idea, what is the reson for that?