Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Challenge: Capturing stdout from a function call.

by johnnywang (Priest)
on Oct 21, 2004 at 18:22 UTC ( [id://401256]=note: print w/replies, xml ) Need Help??


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

I asked a similar quetion sometime back: How to capture STDOUT/STDERR of a function. One solution from there was:
use strict; my $out; { open local(*STDOUT), '>', \$out; foo(); } print "Std: $out\n"; sub foo{ print "from foo"; }

Replies are listed 'Best First'.
Re^2: Challenge: Capturing stdout from a function call.
by melora (Scribe) on Oct 21, 2004 at 23:33 UTC
    That looks like a really elegant solution. When I tried it on my system, I ended up with a file named SCALAR(0x17651f0) containing "from foo". What am I missing?
      perl5.8 probably.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found