in reply to Challenge: Capturing stdout from a function call.

use strict; use warnings; use Perl; my $p = Perl->new; my $data = $p->eval(q{ do{ use IO::Scalar; my $result; tie *STDOUT, 'IO::Scalar', \$result; print 'some stuff'; $result; } }); print "|||$data|||\n";

If you want to run a perl script change the print line to do 'somefile.pl';

Replies are listed 'Best First'.
Re^2: Challenge: Capturing stdout from a function call.
by BUU (Prior) on Oct 22, 2004 at 20:51 UTC
    Thats an interesting idea, my only problem is that the entire script has to be recompiled and reexecuted every time I try to run it. The main reason I'm playing with Perl.pm is to be able to "cache" the compilation of perl scripts, for speed purposes. Theoretically, with the Perl->new() method, it will load and compile the script, then I can run it multiple times with the ->run method. Maybe. In your method it would have to get reloaded every time, I think.