According to the Template docs, the third param to process can be a SCALAR ref - just pass in a ref to the variable you want to receive it.
| [reply] |
#!/usr/bin/perl
use strict;
use warnings;
use Template;
my $data = { name => 'Ovid' };
my $template = Template->new;
my $output;
$template->process(\*DATA, $data, \$output);
print $output;
__DATA__
Hello, [% name %]
| [reply] [d/l] |
In general, you can open a scalar as though it were a file.
my $fake_file;
open(my $fh, ">", \$fake_file) or die $!;
print $fh, "foo\n";
print $fh, "bar\n";
print $fake_file;
According to perldoc -f open, you can do this with STDOUT, you just have to close it first.
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
| [reply] [d/l] |
Now *that* is cool. Definitely hadn't stumbled on that tidbit. ++thor
| [reply] |
Open-scalar-as-file is only in fairly recent Perls though (5.8 perhaps?). So if your code has to be portable (such as a CPAN submission), don't do that... yet.
| [reply] |