PersistentPerlとuse encoding ’utf8’;

以下のようなPerl/CGIが、PersistentPerl(SpeedyCGI)だと動いたり動かなかったりする。

#!/usr/bin/perperl -w

use encoding 'utf8';
binmode STDERR, ':utf8';

use strict;
use Encode;
use DBI qw(:sql_types);

apacheのエラーログはこのような感じ。

utf8 "\\x98" does not map to Unicode., referer: http://example.com/xxx.cgi
perperl_backend[14775]: protocol error, referer: http://example.com/xxx.cgi
Premature end of script headers: xxx.cgi, referer: http://example.com/xxx.cgi

スクリプト単体で動かすとまた違ったエラーがでてハングする。

utf8 "\xFF" does not map to Unicode.
utf8 "\xC2" does not map to Unicode.

use encodingをやめてuse utf8にすると動く。もちろん生のPerlではuse encodingでも動く。

PersistentPerlがPerl5.8を知らないんじゃないだろうか。
PersistentPerl-2.22のリリースは2002年9月、Perl5.8のリリースは2002年7月。うーん微妙。
とりあえずuse utf8に書き直し。