Just to clarify a bit on what
ikegami said above (and just to prove it for myself), here's a little test script to demonstrate a run-time choice of output encoding. When you run this on the command line with no args, the output will be iso-8859-15; when you add "utf8" as an option, that will be the output encoding. The template is the same in both cases.
#!/usr/bin/perl
use strict;
use warnings;
use Template;
use Encode;
my $encoding = 'iso-8859-15';
my @testchars = map { encode( $encoding, chr( $_ )) } ( 0xc0 .. 0xff )
+;
if ( @ARGV and $ARGV[0] eq 'utf8' ) {
$_ = decode( $encoding, $_ ) for ( @testchars );
$encoding = 'utf8';
}
my $tmpfile = "test.$$.tt";
open( TMP, ">", "/tmp/$tmpfile" ) or die "/tmp/$tmpfile: $!";
print TMP while (<DATA>);
close TMP;
binmode STDOUT, "encoding($encoding)";
my $tt = Template->new( INCLUDE_PATH => "/tmp" )
or die "template init. error\n";
$tt->process( $tmpfile, { enc => $encoding, testchars => \@testchars }
+ )
or die "template proc. error\n";
__DATA__
<html>
<p>This page should be using [% enc %].</p>
<table>
[% FOREACH i IN [ 0 .. 3 ] -%]
<tr>
[% FOREACH j IN [ 0 .. 15 ] %]
[%- k = i * 16 + j -%]
<td>[% testchars.$k %]</td>
[% END -%]
</tr>
[% END -%]
</table>
</html>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.