[Templates] Win32 and BINMODE
Peter Guzis
PGuzis@encad.com
Wed, 23 Apr 2003 13:34:46 -0700
I was able to replicate this behavior under Win2k on my, admittedly =
outdated, TT 2.52 installation. I believe the problem stems from =
binmode() being automatically invoked while running under Win32. If you =
check Template.pm you'll notice the following line:
$BINMODE =3D ($^O eq 'MSWin32') ? 1 : 0;
Depending on if you tell TT to send output to a file or a filehandle =
your results will vary.
## begin code ##
use strict;
use Template;
my $file =3D 'c:/path/file.txt';
my $template =3D new Template() or die;
my $data =3D qq!
[% 'a' %]
[% 'b' %]
[% 'c' %]
[% FOREACH a =3D [1..10] %]
[% a %]
[% END %]
!;
# pass filename to process (implicit binmode) =3D LF only
$template->process (\$data, undef, $file);
# pass filehandle to process (no binmode) =3D CR/LF
open (OUT, ">$file") or die;
$template->process (\$data, undef, \*OUT);
close (OUT);
# pass filehandle to process (explicit binmode) =3D LF only
open (OUT, ">$file") or die;
binmode (OUT);
$template->process (\$data, undef, \*OUT);
close (OUT);
## end code ##
Here are your options I see at this point.
1. Pass a filehandle (non-binmode) to process() instead of a file name
2. Globally override the binmode behavior or Template.pm with: =
$Template::BINMODE =3D 0
3. Add/ask for addition a configuration option to be added per =
invocation of Template->new() and/or $template->process()
Peter Guzis
Web Administrator, Sr.
ENCAD, Inc.
- A Kodak Company
email: pguzis@encad.com
www.encad.com=20
-----Original Message-----
From: Kenneth Morse, Ilium Software [mailto:knsp@iliumsoft.com]
Sent: Wednesday, April 23, 2003 12:40 PM
To: templates@template-toolkit.org
Subject: [Templates] Win32 and BINMODE
Hello,
I've noticed using the Template Toolkit on Windows that the eol =
termination output from process() is different if STDOUT is used than it =
is if a file is used. For example:
$tt->process($ARGV[0], $vars)
when this form is used and STDOUT is redirected to a file, the =
termination is appropriate for a Win32 platform (CRLF).
$tt->process($ARGV[0], $vars, $ARGV[1])
when this form is used (ARGV[1] specifies the output file) the =
termination is only LF which is not appropriate for a Win32 text file.
Is this configurable somewhere?
Thanks,
Ken