perlunicodetemplate-toolkit

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 object using this config:

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

Solution

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