[Israel.pm] print to 2 places at the same time

Offer Kaye oferk at oren.co.il
Tue Jun 1 10:03:07 PDT 2004


Hi mongers,
I'm trying to use advice from "perlfaq5" and print to 2 places at once
(STDOUT and a file) using "tee". However, in my case I have to intercept the
prints to the filehandle with prints just to STDOUT. Example code:

open(OUT,"| tee foo.txt") or die "tee foo no good: $!\n";
print OUT "foobar\n";
print "AAAAAAAAARRRRRRRRRGGGGGGGGG\n";
print OUT "barfoo\n";
close(OUT) or die "wtf?\n";

The problem is, the above doesn't print:
foobar
AAAAAAAAARRRRRRRRRGGGGGGGGG
barfoo

As you would expect. It instead prints:
AAAAAAAAARRRRRRRRRGGGGGGGGG
foobar
barfoo


This happens even of I do "$|=1;" at the beginning of the script.
Anyone have any idea what is happening?
Anyone have any workaronds?

Thanks in advance,
----------------------------------
Offer Kaye





More information about the Perl mailing list