I am trying to speed up an existing script by focusing on a loop that runs through individual files and returns values to an array and several hashes. I think this can be done using forks, but I'm not sure how to return the data from the children to the parent.
Reading the documentation it says you can only return one data structure, and to keep it small. Is it possible to return all of the values I've listed in the pseudo code below?
If so(assuming it's going to involve making one data structure containing references to all of these, how would you go about that, and then how would you dereference it once it's back to the parent? (I have struggled immensely with referencing/dereferencing!)
#pseudo code
use Parallel::ForkManager;
$threads = 20
my $pfm = new Parallel::ForkManager( $threads );
FOREACH: foreach my $thing(keys %{$things_hr}) {
my $pid = $pfm->start and next;
#do stuff
push @names, $name;
#do stuff
$thing{$name}{a} = $value1;
$thing{$name}{b} = $value2;
#do stuff
$list{$id}{$name}{b} = $b;
$list{$id}{$name}{e} = $b1;
$list{$id}{$name}{a} = 0;
$list{$id}{$name}{c} = $ar->[$id][3];
$list{$id}{$name}{i} = $ar->[$id][1];
$list{$id}{$name}{j} = $ar->[$id][2];
$list{$id}{$name}{k} = sprintf("%.4f",$ar->[$id][9]);
$pfm->finish;
$pfm->wait_all_children;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|