[Templates] Templates inserting huge files
darren chamberlain
dlc@users.sourceforge.net
Mon, 6 Jan 2003 11:23:55 -0500
* Shannon, Bryan <BShannon@Tribune.com> [2003-01-06 10:34]:
> However, the problem is that the output files that I'm INSERTing are
> getting larger all the time (hundreds and hundreds of megs), and it's
> causing the process to use way too much memory (and sometimes my Perl
> commits suicide!).
Rather than making them actual template variables, you could write a
plugin that wraps around IO::File:
package Template::Plugin::BigAssFile;
use base qw(Template::Plugin);
use IO::File;
sub new {
my ($class, $context, $file) = @_;
# Insert error checking, etc
bless { _FILE => IO::File->new($file) } => $class;
}
sub nextline {
my $self = shift;
my $fh = $self->{ _FILE };
my $line = <$fh>; # force scalar context
return $line;
}
1;
Then you could use it as:
[% USE BigAssFile("/my/big/file");
WHILE (line = BigAssFile.nextline);
# line will already have newlines and such
line;
END;
%]
Only tested quickly, but it should work.
(darren)
--
Let face facts, shall we? There is a very real possibility
that this could also be the *last* day of the rest of your life.
-- Dave Henry