Friday, January 7, 2011

perl: print more than one file at once

#How do I print to more than one file at once?

use autodie;

open(F1, ">1.out");
open(F2, ">2.out");
open(F3, ">3.out");

use IO::Tee;
#use Tie::FileHandle::Multiplex;

#To connect one filehandle to several output filehandles, you can use the IO::Tee or Tie::FileHandle::Multiplex modules.

#If you only have to do this once, you can print individually to each filehandle.

foreach my $fh (F1, F2, F3) {
   print $fh "whatever\n";
}

No comments: