Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: stdout question

by Fastolfe (Vicar)
on Nov 26, 2001 at 02:09 UTC ( [id://127432]=note: print w/replies, xml ) Need Help??


in reply to stdout question

IO::Scalar or IO::String may be what you want, to create a filehandle that represents the data in a Perl scalar. Combine that with select, which tells Perl what "default" file handle to use for things like print, and you can send data directly to the scalar as if it were a filehandle. Note that this is incompatible with things like system or exec, since select's defaults only apply to Perl code itself. You aren't really affecting STDOUT, just the "implicit" file handle Perl uses for its functions. This may be sufficient for your needs.
use IO::String; my $buffer; my $oldfh = select(new IO::String \$buffer); eval ' print "This is a test."; ' or die; select($oldfh); print "Captured: '$buffer'\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://127432]
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: (3)
As of 2024-04-19 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found