MCE::Shared::Handle - Handle helper class
This document describes MCE::Shared::Handle version 1.699_010
# 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( \¶llel ) 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;
Helper class for MCE::Shared.
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.
expr
filehandle
open
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 );
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.
reference
file handle
{ Array, Handle, Hash, Minidb, Ordhash, Scalar, Sequence }
Perl must have the IO::FDPass module installed for MCE::Shared to pass a file_descriptor higher than 2 to the shared-manager process.
file_descriptor
Implementation inspired by Tie::StdHandle.
MCE, MCE::Core, MCE::Shared
Mario E. Roy, <marioeroy AT gmail DOT com>
To install MCE, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MCE
CPAN shell
perl -MCPAN -e shell install MCE
For more information on module installation, please visit the detailed CPAN module installation guide.