NAME
Multi - Print to multiple filehandles with one output call
SYNOPSIS
use FileHandle::Multi;
$mult_obj=new FileHandle::Multi;
$mult_obj->open('>-');
$mult_obj->open('>file');
$mult_obj->open(">$file");
$mult_obj->open('>>file2');
$mult_obj->print("This will be printed to several filehandles\n");
$mult_obj->printf("This will be printed to %d filehandles\n",
scalar @{$mult_obj->{handles}});
$mult_obj->autoflush();
@handle_refs = $mult_obj->members();
$mult_obj->output_field_separator(':');
$mult_obj->output_record_separator('\n');
$mult_obj->format_page_number(2);
$mult_obj->format_lines_per_page(66);
$mult_obj->format_lines_left(10);
$mult_obj->format_name('AN_REPORT');
$mult_obj->format_top_name('AN_REPORT_TOP');
$mult_obj->format_line_break_characters('\n');
$mult_obj->format_formfeed('\l');
$mult_obj->close();
DESCRIPTION
This module requires that the user have the FileHandle module installed (it comes with the perl distribution). Create objects for each of the output filehandles you'll have - then call the print() and printf() methods to send output to ALL the filehandles associated with an object.
EXAMPLES
Look at the SYNOPSIS section. Also, here is a simple implementation of the unix tee(1) program (non-append mode):
#!/local/bin/perl
use Multi;
$mh=new Multi;
$mh->open('>-');
for (@ARGV) { $mh->open(">$_"); }
while (<STDIN>) { $mh->print($_); }
BUGS
I don't think using my()s the way I am in the open() method is all that good. binmode isn't supported, but I don't see anybody using that anyways. In order to use fcntl(), fileno(), or flock() you'll have to access the filehandles yourself by calling members(). There's no write() yet (but I'm working on it!). Also, any limitations to the FileHandle module also apply here.
AUTHOR
Nem W Schlecht (nem@plains.nodak.edu). Comments, bugs fixes, and suggestions welcome.