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); 
planetp
  • 14,248
  • 20
  • 86
  • 160

2 Answers2

10

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).

Community
  • 1
  • 1
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
1
$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.

daxim
  • 39,270
  • 4
  • 65
  • 132