The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MCE::Shared::Handle - Handle helper class

VERSION

This document describes MCE::Shared::Handle version 1.700

SYNOPSIS

   # shared
   use MCE::Shared;

   my $fh = MCE::Shared->handle( "<", "sample.fasta" );

   # demo
   use MCE::Hobo;
   use MCE::Shared;

   my $ofh = MCE::Shared->handle( '>>', \*STDOUT );
   my $ifh = MCE::Shared->handle( '<', '/path/to/input/file' );

   # output is serialized (not garbled), but not ordered
   sub parallel {
      $/ = "\n"; # can set the input record separator
      while (my $line = <$ifh>) {
         printf {$ofh} "[%5d] %s", $., $line;
      }
   }

   MCE::Hobo->create( \&parallel ) for 1 .. 4;

   $_->join() for MCE::Hobo->list();

   # handle functions
   my $bool = eof($ifh);
   my $off  = tell($ifh);
   my $fd   = fileno($ifh);
   my $char = getc($ifh);
   my $line = readline($ifh);

   binmode $ifh;

   seek $ifh, 10, 0;
   read $ifh, my($buf), 80;

   print  {$ofh} "foo\n";
   printf {$ofh} "%s\n", "bar";

   open $ofh, ">>", \*STDERR;
   syswrite $ofh, "shared handle to STDERR\n";

   close $ifh;
   close $ofh;

DESCRIPTION

Helper class for MCE::Shared.

API DOCUMENTATION

new ( expr )
new ( mode, expr )
new ( mode, reference )

Constructs a new object by opening the file whose filename is given by expr, and returns a filehandle. Unlike open, MCE::Shared will emit an error message and stop if an error occurs during opening of the file.

   use MCE::Shared;

Simple examples to open a shared file for reading:

   $fh = MCE::Shared->handle( "< input.txt" );
   $fh = MCE::Shared->handle( "<", "input.txt" );
   $fh = MCE::Shared->handle( "<", \*STDIN );

and for writing:

   $fh = MCE::Shared->handle( "> output.txt" );
   $fh = MCE::Shared->handle( ">", "output.txt" );
   $fh = MCE::Shared->handle( ">", \*STDOUT );

LIMITATION

When passing a reference, be sure to construct its file handle associated with reference prior to starting the shared-manager process. Constructing a shared object { Array, Handle, Hash, Minidb, Ordhash, Scalar, Sequence } starts the manager process automatically.

Perl must have the IO::FDPass module installed for MCE::Shared to pass a file_descriptor higher than 2 to the shared-manager process.

CREDITS

Implementation inspired by Tie::StdHandle.

INDEX

MCE, MCE::Core, MCE::Shared

AUTHOR

Mario E. Roy, <marioeroy AT gmail DOT com>