Thanks for reply.
Problematic string came from chr(). I didn't know I can paste 'é' at PerlMonk, I tried to create it with chr(hex()). And I stumbled.
The OP of this thread Bug in Template? said he decode with database driver and print it in Template with like this.
Template wants encoded bytes, not decoded characters. This prints "#�#".my $t =Template->new(); $t->process("his.tmpl", {lines=>\@vars}, "output.html" ) or die $t->error();
And below is Template for that.#!/usr/bin/perl use strict; use warnings; use Encode qw(decode encode); use Template; my($a,$decoded); #input bytes to $a $a=`perl -CS -e "use utf8;print 'é'"`; #decode it to character $decoded=decode('UTF-8', $a); #this will print replacement character to test_out1.html my $t=Template->new(); $t->process("test.tmpl",{a=>$decoded},"test_out1.html");
Encode $a to bytes will work.<html> <head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" +> </head> <body> #[% a %]# </body> </html>
There seems huge confusion around Template Tool Kit's Encoding problem here in Japan. My conclusion so far: "pass encoded bytes to Template, not decoded character".#!/usr/bin/perl use strict; use warnings; use Encode qw(decode encode); use Template; my($a,$decoded,$encoded); #input bytes to $a $a=`perl -CS -e "use utf8;print 'é'"`; #decode it to character $decoded=decode('UTF-8', $a); $encoded=encode('UTF-8', $decoded); #this is good my $t=Template->new(); $t->process("test.tmpl",{a=>$encoded},"test_out2.html");
In reply to Re^2: "ISO-8859-1 0x80-0xFF" and chr()
by remiah
in thread "ISO-8859-1 0x80-0xFF" and chr()
by remiah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |