note
karlgoethebier
<p>Stolen, cannibalized and slightly adopted from this older thread: [id://1127540]:</p>
<c>
#!/usr/bin/env perl
# http://www.perlmonks.org/?node_id=1202693
# $Id: loop.pl,v 1.2 2017/11/04 11:02:41 karl Exp karl $
use strict;
use warnings;
use MCE::Loop;
use Time::HiRes qw( time );
use feature qw(say);
my $file = q(data.txt);
MCE::Loop::init( { max_workers => 4, use_slurpio => 1 } );
my $start = time;
my @result = mce_loop_f {
my $slurp_ref = $_[1];
my @column;
open my $fh, '<', $slurp_ref;
binmode $fh, ':raw';
while (<$fh>) { push @column, substr( $_, 10, 1 ) }
close $fh;
MCE->gather(@column);
# sleep 2;
}
$file;
say join( '', @result );
printf "Took %.3f seconds\n", time - $start;
__END__
</c>
<p>Thanks to [marioroy].</p>
<p>See also [mod://MCE].</p>
<p><b>Update:</b> To avoid the call to <c>binmode</c> please see [id://1194998].</p>
<p>Regards, Karl</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-1001958">
<p>«The Crux of the Biscuit is the Apostrophe»</p>
<p><c>perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'</c>[href://?node_id=1001958#env|Help]</p>
</div></div>
1202693
1202693