Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Redirecting STDOUT to file and screen as an afterthought, on Windows.

by LanceDeeply (Chaplain)
on Nov 03, 2004 at 11:00 UTC ( #404936=note: print w/replies, xml ) Need Help??


in reply to Redirecting STDOUT to file and screen as an afterthought, on Windows.

To log to file without modifing all your existing prints use select to make print automatically go to a filehandle.

use FileHandle; my $log = 0; print "Do you want to log to a file?"; my $resp = <STDIN>; if ($resp =~ /^y/i) { my $fh = new FileHandle; my $filepath = "c:\\stdout.txt"; $fh->open(">> $filepath") || die "could not open log file $filepat +h"; select $fh; } # # this will go to log file if $resp was y # print "Holla!\n";
-HTH

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-05-11 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (111 votes). Check out past polls.

    Notices?