in reply to Template Toolkit and different encodings
#!/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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Template Toolkit and different encodings
by morgon (Priest) on Dec 23, 2010 at 11:14 UTC | |
by graff (Chancellor) on Dec 23, 2010 at 14:21 UTC | |
by morgon (Priest) on Jan 07, 2011 at 15:50 UTC |