in reply to reading files and directories, part two

I read your question as asking, "How do I print to STDOUT and OUTFILE simultaneously?" This response answers what I think you're asking.

Though it may be overkill for a short script, there is always the IO::Tee module on CPAN, which allows you to write to multiple filehandles with a single print call.

From the POD, here is an example:

use IO::Tee; $tee = IO::Tee->new($handle1, $handle2); print $tee "foo", "bar";

So the idea would be to call IO::Tee->new(...) with OUTFILE and STDOUT as its arguments. To do that, I believe you would do it like this:

$tee = IO::Tee->new(\*STDOUT, \*OUTFILE); print $tee "Your data here" if .....

Or you could try a "roll your own" solution by using the aliasing characteristic of a for loop to multiplex the filehandles for you, like this:

use strict; use warnings; open my $fh, ">test.out" or die "Can't open outfile."; print $_ "Test string.\n" for \*STDOUT, $fh; close $fh;

Hope this helps!


Dave