in reply to Re: Re: Dumping data
in thread Dumping data

Just add the following stub to the beginning of your perl program will allow your script to print to both STDOUT and results.txt. The stub works transparently so you do not have to change your print statements.
use strict; use warnings; # ---- add this stub to the start of your program ---- use IO::File; use IO::Capture::Stdout; our $capture; BEGIN{ $capture = IO::Capture::Stdout->new(); $capture->start(); } END{ $capture->stop(); my $f = new IO::File "results.txt", "w" or die "Can not create file" +; while (defined ($_ = $capture->read())) { print $f "$_"; print "$_"; } } # ---- your stuff here ---- print "Test Line One\n"; print "Test Line Two\n"; print ""; print "Test Line Three\n";

Replies are listed 'Best First'.
Re: Re: Re: Re: Dumping data
by Anonymous Monk on Jan 01, 2004 at 02:04 UTC
    Is it just me, or does IO::Capture seem like a stupid idea?
      If you have 100's of print statements in your code, would you rather use a transparent stub or go and modify everyone of your print statements? Please don't make such comment if you don't understand the code.

        If you have 100's of print statements in your code, would you rather use a transparent stub or go and modify everyone of your print statements?
        Neither. I'd use select.
        Please don't make such comment if you don't understand the code.
        So you don't see IO::Capture as poorly thought out (it would appear you don't understand it so well)?