schetchik has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Monks

I use Template module and array reference for OUTPUT. But data, which I use for substitution into templates is decoded, ,
so I get wide characters in my result data, because Template doesn't encode it by default.
I've found fourth parameter in process method, that has binmode option, but it doesn't work for output to array ref.
May be I looked bad?

Help, please.
  • Comment on encode params in Template into array ref

Replies are listed 'Best First'.
Re: encode params in Template into array ref
by Anonymous Monk on Dec 09, 2014 at 17:08 UTC
    Encode your strings manually then...
      Now i manualy encode result array reference of strings, but it's not comfortably.
        I'm not really sure what you mean by 'array', but I see that Template talks about 'hash array' (strange terminology... but whatever).
        use Encode; my $enc = Encode::find_encoding('utf-8'); # or some other encoding... my %encoded = map { $enc->encode($_), $enc->encode( $decoded{$_} ) } keys %decoded;
        Looks alright to me...
Re: encode params in Template into array ref
by LanX (Saint) on Dec 09, 2014 at 16:41 UTC
    Could you please post a little example reproducing the problem?

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      use strict; use v5.14; use utf8; use Template; my $value = "...."; #some unicode text with wide characters here my $template = Template->new(); my $result = [ ]; $template->process( "1.tt", { value => $value }, $result ); say @$result;
      And i got warning:
      Wide character in say at 1.pl line 17.