Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: reuse STDOUT after it was closed

by rodion (Chaplain)
on Mar 12, 2007 at 10:54 UTC ( #604314=note: print w/replies, xml ) Need Help??


in reply to reuse STDOUT after it was closed

Depending on the structure of your code, you could use somehting as simple as localizing STDOUT.
print "Msg to original STDOUT\n"; { local *STDOUT; open(STDOUT, ">my_file") ; select STDOUT; $| = 1; print "msg to Redirected STDOUT\n"; } print "Msg to original STDOUT again\n";
Note that the localized copy of STDOUT will be used by any subs called from within the block (after the local), unlike with "my", but from your post, I think that's what you want. (Localizing STDOUT when you change it is good practice in any case.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2021-09-28 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?