Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Challenge: Capturing stdout from a function call.

by eclark (Scribe)
on Oct 22, 2004 at 18:17 UTC ( #401618=note: print w/replies, xml ) Need Help??

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 '';

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 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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://401618]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2022-05-23 14:57 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.