でUTF-8のページを表示する

#!/usr/bin/perl -w
use strict;
use Encode;
use encoding('euc-jp');
binmode(STDERR, ':raw :encoding(euc-jp)');
binmode(STDOUT, ':raw :encoding(utf8)');

my $header = "Content-type:text/html; charset:utf-8\n\n";
print $header;
my $str = 'あいうえお';
print "$str\n";

ソースの文字コードeuc-jp


とりあえず、UTF-8
あいうえお
と表示されました


httpヘッダ

http://hoge.com/utf8.cgi

GET /utf8.cgi HTTP/1.1
Host: mydebian
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: ja,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cache-Control: max-age=0

HTTP/1.x 200 OK
Date: Thu, 06 Mar 2008 09:28:10 GMT
Server: Apache/2.2.3 (Debian) PHP/5.2.0-8+etch7
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset:utf-8


Perl5.8 utf8フラグ PerlIOレイヤ よく分ってないけど、参考ページ