Nem W Schlecht > IO-File-Multi > IO::File::Multi

Download:
IO-File-Multi-1.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.02   Source  

NAME ^

Multi - Print to multiple filehandles with one output call

SYNOPSIS ^

    use IO::File::Multi;
    $mult_obj=new IO::File::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 IO::File 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 IO::File::Multi;
  $mh=new IO::File::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 IO::File module also apply here.

It has been pointed out to me that multiple open() calls on the same file under MacOS will fail. Hopefully, the carp() call will help with catching this.

AUTHOR ^

Nem W Schlecht (nem@plains.nodak.edu). Comments, bugs fixes, and suggestions welcome.

syntax highlighting: