in reply to Is it possible to write to 2 files, eg. print LOGFILE,TEMP 'hello'?

From the Perl Cookbook.

"If you don't mind forking, open a filehandle that's a pipe to a tee program:"

And then an example adapted from the same section is:

my ($file1, $file2, $file3) = qw/this.out that.out other.out/; my $fh; open $fh, "| tee $file1 $file2 $file3 > /dev/null" or die $!; print $fh "data\n" or die $!; close $fh or die $!;

Of course this will only be of value to those whos operating systems support tee (Linux / Unix, for example). The reason for the redirection to /dev/null is because tee typically copies its output on STDOUT. If you don't want that extra copy you redirect it to /dev/null (the garbage can).

  • Comment on Re: Is it possible to write to 2 files, eg. print LOGFILE,TEMP 'hello'?
  • Download Code