Next, workers send data to the manager process via MCE->gather instead of sending to STDOUT.
use strict;
use warnings;
use MCE::Loop;
my @patterns = ( "biopattern1", "biopattern2", "biopattern3" );
my $search = join('|', @patterns);
my $regex = qr/$search/;
open my $fh, "gunzip -c in.fastq.gz |" or die "open error: $!";
MCE::Loop->init(
max_workers => 4,
chunk_size => 50,
RS => "\n@"
);
my @found = MCE::Loop->run( sub {
my ( $mce, $chunk_ref, $chunk_id ) = @_;
for my $i ( 0 .. $#{ $chunk_ref } ) {
if ( $chunk_ref->[$i] =~ /$regex/ ) {
MCE->gather( $chunk_ref->[$i] );
}
}
}, $fh );
MCE::Loop->finish();
close $fh;
print join('', @found);