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

Srikanth Madani srikanth.madani at vodafone.com
Wed Jun 2 01:07:02 PDT 2004


Offer Kaye wrote:
> This happens even of I do "$|=1;" at the beginning of the script.
BTW, from what I understand, the $| variable does not guarantee that the OS
will actually perform an instantaenous write.
Can someone comment on this?


Eli wrote:
>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").

Yes, IO:Tee is an alternative; here's sample code that uses it.

#______________________code starts_____________________
use IO::Tee;
#Multiplex output to multiple output handles

my $tee = IO::Tee->new ( ">$first_file", ">$second_file");
#Bind $tee to $first_file and $second_file
#Notice that file handles are not used.

$| = 1;
#Set OUTPUT_AUTOFLUSH

print $tee "\nMail comments about $0 to
wishIwas.onHoliday\@ko-phangan.th\n";

$tee->flush();
#Flush the output buffer
#______________________code ends_____________________


Cheers,
Srikanth Madani
Murphy's Law is recursive. Washing your car to make it rain doesn't work.




More information about the Perl mailing list