http://qs321.pair.com?node_id=1214682

rajaman has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am processing a text file (code shown below), chunk by chunk. For each text chunk, I do some processing shown in the while loop in the code below. I am collecting the result of the processing in a hash (%hashunique). How can I do parallel processing on this code. For example, run in parallel 10 instances of while loop, each processing 10 different chunks of text from the input file. At the end of processing, all results are saved in %hashunique.

I checked some modules, but could not figure out how to apply these on my code below.

Thanks a lot!

#!/usr/bin/perl use strict; use warnings; use Data::Dumper qw(Dumper); use re::engine::RE2; use List::MoreUtils qw(uniq); use Sort::Naturally; #This program reads abstract sentence file and produces output with th +e following format: # if ($#ARGV != 1) { print "usage: program arguments\n"; } my $inputfile1=$ARGV[0]; my $outputfile = $ARGV[1]; my %hashunique=(); open(RF, "$inputfile1") or die "Can't open < $inputfile1: $!"; open(WF, ">$outputfile"); #open for output $/ = ''; #this sets the delimiter for an empty line while (<RF>) { my @one = split /\n/ , $_; my ( $indexofdashinarray ) = grep { $one[$_] =~ /\-\-/ } 0..$#one; for (my $i=0;$i<=$#one;$i++) { next if $i==0; next if $one[$i] =~ /^\-\-$/; while ($one[$i] =~ m/(\b)D\*(.*?)\*(.*?)\*D(\b)/g) { unless ($hashunique{"D$2"}) { $hashunique{"D$2"}="$3"; } else { $hashunique{"D$2"}=$hashunique{"D$2"}.'|'."$3"; } } } } foreach my $i (nsort keys %hashunique) { $hashunique{$i} = join ( "\|", uniq split /\|/ , $hashunique{$i}); print WF "$i=>$hashunique{$i}\n"; } close (RF); close (WF);