How to extract data from Parallel::ForkManager in perl -


i using google explaining issue.
have calculated latency time search request on google , printing it.
now, need data max time, min time, average time. trying push data array can manipulated later on. array coming out blank. seems limitation of parallel-forkmanager. please suggest work around.

my code:

use parallel::forkmanager; use www::mechanize; use lwp::useragent; use time::hires qw/gettimeofday/; use time::format qw/%time/; use posix       qw( strftime ); use time::hires qw( gettimeofday ); $count=5; @arr=(); $pm = new parallel::forkmanager($count);    for(1..$count)   {        $pm->start , next;         $m = www::mechanize->new();   $m->get( "http://www.google.com" );   $s1=gettimeofday;   ($secs, $microsecs) = gettimeofday();   print strftime("%h:%m:%s", localtime($secs)) . sprintf(".%04d",  $microsecs/10);   $m->submit_form(   form_number => 1,   fields    => {q=>'abcd'},   );    print " ";   print $m->title;   print " ";   $s2=gettimeofday;   ($secs, $microsecs) = gettimeofday();   print strftime("%h:%m:%s", localtime($secs)) . sprintf(".%04d",     $microsecs/10);   $s3=$s2-$s1;   $s3=$s3*1000;   print "  $s3\n";   push(@arr,$s3);   $pm->finish   }    $pm->wait_all_children; ## wait child processes foreach(@arr) { print "$_\n"; } 

you need add run_on_finish callback manager instance аnd call finish method 2 arguments child. can second parameter of finish call sixth argument of run_on_finish callback.

# parent @arr; $pm->run_on_finish(sub {     push(@arr, ${$_[5]}); });  # child $val = 42; $pm->finish(0, \$val);  # parent $pm->wait_all_children(); print($_, "\n") @arr; 

Comments