#!/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 (); 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__

This page should be using [% enc %].

[% FOREACH i IN [ 0 .. 3 ] -%] [% FOREACH j IN [ 0 .. 15 ] %] [%- k = i * 16 + j -%] [% END -%] [% END -%]
[% testchars.$k %]