This seems not a problem of Template. I also want advice for this.
“Séan”'s é may be 00E9 of unicode table http://www.utf8-chartable.de/unicode-utf8-table.pl. I thought decode it to perl internal utf8 and pass them to Template encoding it utf8 will work. But it is not work. Without Template, there is strange behavior.
#!/usr/bin/perl
use strict;
use warnings;
use Encode qw(is_utf8 encode decode);
use Template;
my(@raw, @decoded_internal_utf8,@encoded_raw_utf8,@encoded_internal_ut
+f8);
my @chars=hex('00C0') .. hex('00F0'); #target characters
#my @chars=hex('3041') .. hex('3096'); #hiragana
foreach my $code ( @chars ){
my($raw, $chr);
$raw =chr($code);
if ( is_utf8($raw) ){
$chr=$raw;
} else {
$chr=decode('utf8',$raw);
}
push @raw, $raw;
push @decoded_internal_utf8, $chr;
push @encoded_raw_utf8 , encode('utf8', $raw);
push @encoded_internal_utf8, encode('utf8', $chr);
}
print "======================\n";
print "perl=$^X : version=$]\n";
print "1.###raw\n";
print "#$_#\n" for @raw;
print "2.###decoded_intenal_utf8\n";
#print "#$_#\n" for @decoded_internal_utf8;
print "3.###encoded_raw_utf8\n";
print "#$_#\n" for @encoded_raw_utf8;
print "4.###encoded_internal_utf8\n";
print "#$_#\n" for @encoded_internal_utf8;
It is strange No3 only works at this case. I usualy print characters with No 4. Japanese characters like "hiragana" seems to have no problem( for example,'3041' .. '3096').
I saw similar problem at Why Doesn't Text::CSV_XS Print Valid UTF-8 Text When Used With the open Pragma?. At that time, I didn't understand well and thought newer version would have no problem... Is this the same trouble? I tried with 5.012002 and 5.014002. They print exact same output except version number.