note
ikegami
<p>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.
<p>I just wanted to provide a cleaned up version of your code (with a few micro-optimizations).
<c>
#!/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} });
}
</c>
1214682
1214682