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

Eli Billauer eli at billauer.co.il
Tue Jun 1 12:52:44 PDT 2004


Correct me if I'm wrong, but as long as one path goes through an 
external process and the second goes directly from Perl's "print", there 
is no way to control which comes first. In particular, you have no way I 
can think of to be sure that the application "tee" has finished sending 
its data.

I would suggest to use a Perl module named IO:Tee from CPAN. Never tried 
it, but how bad can it bee? ("bee" as in "tee").

That would make sure that the order of output is kept, with no 
autoflushes needed.

Good luck,
   Eli

Offer Kaye wrote:

>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
>
>
>_______________________________________________
>Perl mailing list
>Perl at perl.org.il
>http://www.perl.org.il/mailman/listinfo/perl
>
>
>  
>


-- 
Web: http://www.billauer.co.il





More information about the Perl mailing list