11

I have this warning every time I run my CGI-script (output is rendered by Template::Toolkit):

Wide character in print at /usr/local/lib/perl5/site_perl/5.8.9/mach/Template.pm line 163.

What's the right way to eliminate it?

I create the tt object using this config:

my %config = (
       ENCODING     => 'utf8',
       INCLUDE_PATH => $ENV{TEMPLATES_DIR},
       EVAL_PERL   => 1,
}
my $tt = Template->new(\%config); 
4

2 に答える 2

10

これを呼び出しの前に置い$tt->process()て、出力を自動的にエンコードします。

binmode STDOUT, ':utf8';

編集daximが述べたように、TTのエンコーディング機能を利用することは可能です:

$tt->process($infile, $vars, '-', { binmode => ':utf8' })

これは、ファイル名が読み取り用に開かれたとき、および書き込み用に開かれたときに'-'ファイル名が提供する、広く使用されている規則に依存しています。STDINSTDOUT

編集2:ところで、後者の方法はmod_perl(2.0.5)では機能しないようです。

于 2010-03-18T09:11:58.000 に答える
1
$tt->process($infile, $vars, $outfile, { binmode => ':encoding(UTF-8)' })

これはhttp://search.cpan.org/perldoc?Template#process%28%24template%2C_%5C%25vars%2C_%24output%2C_%25options%29に記載されています。

于 2010-03-18T12:09:05.430 に答える