To expand here (as I was about to post much of
BrowserUk's point 1), I expect you'll get much better performance if you swap to slurp mode, specifically because you won't interleave reads. It also means that which ever thread reads first will almost assuredly finish its processing before thread 2 finishes its read, so your wall time will be closer to n reads, 1 process, 1 hash transfer. Perhaps something like (untested):
sub parseLines{
my $content = do {
open my $in, '<', $_[0] or die "Open failed $_[0]: $!";
local $/;
<$in>;
};
my %hash;
for (split /(?<=\n)/, $content) {
next unless /^\@HWI/;
my ($header) = split(/ /, $_);
$hash{$header} = 1;
}
return \%hash;
}
Note the indirect filehandle (it automatically closes when it goes out of scope) and the failure test on the
open. If your file is very large, I believe (I could be wrong) that the
for(split) construct will be abusive of memory. In that case, you could craft it as a streaming parser as:
for ($content =~ /(.*\n?)/g) {
my $line = $1;
next unless $line =~ /^\@HWI/;
my ($header) = split(/ /, $line);
$hash{$header} = 1;
}
It's plausible that slurp mode alone wouldn't be enough to force sequential reads, in which case it might make sense to add a shared read lock.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.