tags:

views:

166

answers:

1

I need to output the same text to two different files (it is a application requirement, which I am testing). Now, I do not wish to open two file handles, write two lines to each, then close them a dozen times in my code.

Is there a simple way, perhaps using a single line in Perl (but not in the CLI!), to send the same text to two different files?

+17  A: 

Use IO::Tee.

From the documentation's example:

use IO::Tee;
$tee = IO::Tee->new($handle1, $handle2);
print $tee "foo", "bar";
Rob Kennedy
thanks the solution worked well :-)
gagneet