in reply to Template Toolkit output to a scalar?

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

Replies are listed 'Best First'.
Re^2: Template Toolkit output to a scalar?
by theguvnor (Chaplain) on Jan 15, 2005 at 17:34 UTC
    Now *that* is cool. Definitely hadn't stumbled on that tidbit. ++thor

    [Jon]

        Definitely 5.8. You can do something similar with IO::Scalar with 5.6 - I've got code that checks the perl version, and if 5.8, uses the \$scalar trick, but if 5.6, uses IO::String. Which, of course, doesn't actually come with 5.6, but if you are making a CPAN submission, you can easily put a pre-req on IO::String. Maybe not quite as easy to do if you only want the pre-req for 5.6, but still possible.