jmmach80 has asked for the wisdom of the Perl Monks concerning the following question:
At work, I'm in the middle of multi-threading a script that parses a lot of very large text files, in addition to various other things. The script usually takes over an hour to run, which is annoying, so I decided to multi-thread the parts of the script that taking forever. Anyway, originally I was only needing a small subset of data out of the text files. The code looked something like this...
use Threads;
use Threads::Shared;
my %hash : shared;
.
.
.
while (my $line = <FH>) {
chomp($line);
lock(%hash);
if($line =~ /regex/) {
my @parts = split('|', $line);
$hash{$file} = &share({});
share ( $hash{$file}{start} ); # for pulling start time from file
share ( $hash{$file}{stop} ); # for pulling stop time from file
$hash{$file}{start} = $parts[ 11]
$hash{$file}{stop} = $parts[ 13]
}
}
.
.
.
... This is a short simplified generic snippet from what I can remember off of the top of my head. Doing the above worked perfectly fine; however I realized that I needed additional information out of the text file. Basically, I'm trying to figure out how to correctly share a two-dimensional hash that references (i think) an array. I tried something like this, but it didn't work...
use Threads;
use Threads::Shared;
my %hash : shared;
.
.
.
my $i : shared = 0;
while (my $line = <FH>) {
chomp($line);
lock(%hash);
if($line =~ /regex/) {
$hash{$file} = &share({});
share ( $hash{$file}{certain_row_type}->[$i] );
$hash{$file}{certain_row_type}->[$i] = $line;
$i++;
}
}
.
.
.
So, basically every time we pattern match a certain row type we update the hash. I probably left some details out, but like I said I'm trying to recreate this from memory. I hope what I'm asking makes sense. I have no idea if what I'm trying to do above is even legal; which I guess it's not because I always get the, "can't start threads" message. I actually tried a bunch of other ways to share this hash, but nothing works. Any help would certainly be appreciated.
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sharing Hash Question
by BrowserUk (Patriarch) on Jul 04, 2012 at 18:28 UTC | |
by frozenwithjoy (Priest) on Jul 04, 2012 at 20:16 UTC | |
by BrowserUk (Patriarch) on Jul 04, 2012 at 20:19 UTC | |
by frozenwithjoy (Priest) on Jul 04, 2012 at 20:48 UTC | |
by AnomalousMonk (Archbishop) on Jul 04, 2012 at 21:01 UTC | |
| |
by BrowserUk (Patriarch) on Jul 04, 2012 at 20:57 UTC | |
| |
| |
|
Re: Sharing Hash Question
by ig (Vicar) on Jul 05, 2012 at 09:00 UTC | |
|
Re: Sharing Hash Question
by locked_user sundialsvc4 (Abbot) on Jul 05, 2012 at 14:31 UTC | |
by BrowserUk (Patriarch) on Jul 05, 2012 at 15:32 UTC | |
by jmmach80 (Initiate) on Jul 05, 2012 at 19:17 UTC | |
by BrowserUk (Patriarch) on Jul 05, 2012 at 19:36 UTC | |
by jmmach80 (Initiate) on Jul 05, 2012 at 22:33 UTC | |
|