如果你仅仅想一次打印多个文件,你可以这样做:
for $fh (fh1, fh2, fh3) { print $fh "whatever\n" }
连接一个到多个文件句柄的最简单的方法是使用tee(1)程序(如果你有的话),让它来处理复杂的事情。
open (fh, "| tee file1 file2 file3");
甚至这样写:
# make stdout go to three files, plus original stdout
open (stdout, "| tee file1 file2 file3") or die "teeing off: $!\n";
print "whatever\n" or die "writing: $!\n";
close(stdout) or die "closing: $!\n";
否则,你就只有自己写个多行打印的程序了(你自己的tee程序)。你也可以使用tom christiansen 的程序,http://www.perl.com/cpan/authors/id/tomc/scripts/tct.gz 。这个程序是用perl写的,它提供了更强大的功能。