开发者

How do I eliminate TT's "Wide character in print" warning?

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 objec开发者_StackOverflow社区t using this config:

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


Put this before the call to $tt->process() to have the output automatically encoded:

binmode STDOUT, ':utf8';

Edit: As daxim mentioned, it's possible to utilize TT's encoding facilities:

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

This relies on the widely used convention that the '-' filename gives you STDIN when it's opened for reading, and STDOUT when it's opened for writing.

Edit 2: BTW, the latter way doesn't seem to work for me under mod_perl (2.0.5).


$tt->process($infile, $vars, $outfile, { binmode => ':encoding(UTF-8)' })

This is documented in http://search.cpan.org/perldoc?Template#process%28%24template%2C_%5C%25vars%2C_%24output%2C_%25options%29.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜