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);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parallel-processing the code
by ikegami (Patriarch) on May 17, 2018 at 00:52 UTC | |
by rajaman (Sexton) on May 19, 2018 at 04:12 UTC | |
Re: Parallel-processing the code
by marioroy (Prior) on May 17, 2018 at 04:23 UTC | |
by rajaman (Sexton) on May 17, 2018 at 19:34 UTC | |
by marioroy (Prior) on May 18, 2018 at 04:13 UTC | |
by rajaman (Sexton) on May 19, 2018 at 04:13 UTC | |
Re: Parallel-processing the code
by Marshall (Canon) on May 17, 2018 at 00:17 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Back to
Seekers of Perl Wisdom