Thanks to Greg, I was able to get the result I was looking for, but I am
still curious as to what I was doing wrong w/ the IO::Tee; module.  

open SAVESTDOUT, ">>C:/perl/bin/output/test.txt"
            or die "Open failed";

while (<>) {
              print SAVESTDOUT "$ARGV $1\n"
              and print "$ARGV $1\n"
              and close(ARGV) and next
            if /$RE{URI}{HTTP}{-keep}/;
             }  

-----Original Message-----
From: Brian Volk 
Sent: Friday, July 30, 2004 12:23 PM
To: 'Beginners (E-mail)'
Subject: RE: print to both STDOUT and a file?


Jeff "japhy" Pinyan wrote:
>If you want to make it transparent, use the IO::Tee module.  It's not
>standard, though.

I using IO::Tee and I think I'm getting close.  The output is being sent to
the screen and the phyical output file is being created... but I'm not sure
how to send the @ARGV to the output.txt file as well.



use strict;
use warnings;
use IO::Tee;
use Regexp::Common qw /URI/;

my $dir = "C:/Program Files/OptiPerl/test_dir";
        opendir (TEST, $dir) or die "Can't open $dir: $!";

# ----------- load @ARGV for <> operator below ---------------

@ARGV = map { "$dir/$_" } grep { !/^\./ } readdir TEST;

# ----------- $1 returns the entire URL {-keep} --------------

my $tee = IO::Tee->new( ">>C:/perl/bin/output/test.txt", \*STDOUT ); 

while (<>) {            
              print "$ARGV $1\n"
              and print $tee "\n"
              and close(ARGV) and next
            if /$RE{URI}{HTTP}{-keep}/;
           }

closedir (TEST);


Thanks!

Brian 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to