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


in reply to Parallel-processing the code

As previously mentioned, multi-tasking won't help. This prorgram is I/O-bound, and merging the results of the threads would be as expensive as building the results in the first place.

I just wanted to provide a cleaned up version of your code (with a few micro-optimizations).

#!/usr/bin/perl use strict; use warnings; use feature qw( say ); use Sort::Naturally qw( nsort ); local $/ = ''; # Paragraph mode reads until a blank line. my %grouped; while (<>) { my @lines = split /\n/, $_; for (@lines[1..$#lines]) { next if $_ eq '--'; # Omit if rarely true. ++$grouped{"D$1"}{$2} while /\bD\*([^*]*)\*([^*]*)\*D\b/g; } } for my $k (nsort keys %grouped) { say "$k=>" . join("|", keys(%{ $grouped{$k} }); }