Your Question is Asked Frequently.
You are expected to check the Perl FAQ *before* posting to the Perl newgroup.
perldoc -q file
How do I print to more than one file at once?
Tad, whilst I approve of RTFFAQ answers in principle, I should point
out that the FAQ fails to mention IO::Tee which is probably the
"right" answer.
Could someone please submit a patch to the FAQ.
I would submit it my self but FAQ maintainers seem to ignore me now
since I once submitted a patch containing a typo.
--- perlfaq5.pod Thu Jun 26 17:14:01 2003
+++ perlfaq5.pod+IO::Tee Thu Jun 26 17:25:05 2003
@@ -658,8 +658,8 @@
for $fh (FH1, FH2, FH3) { print $fh "whatever\n" }
To connect up to one filehandle to several output filehandles, it's
-easiest to use the tee(1) program if you have it, and let it take care
-of the multiplexing:
+easiest to use the IO::Tee module or the tee(1) program if you have
+it, and let it take care of the multiplexing:
open (FH, "| tee file1 file2 file3");
@@ -670,6 +670,11 @@
print "whatever\n" or die "Writing: $!\n";
close(STDOUT) or die "Closing: $!\n";
+ require IO::Tee;
+ my $tee = new IO::Tee \*STDOUT, ">file1", ">file2", ">file3"
+ or die "Teeing off: $!\n";
+ print $tee "whatever\n" or die "Writing: $!\n";
+
Otherwise you'll have to write your own multiplexing print
function--or your own tee program--or use Tom Christiansen's,
at
http://www.cpan.org/authors/id/TOMC/scripts/tct.gz , which is
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\