2
我想让子进程写入父类的@array。我读过有关管道,但我对如何真正实现它很困惑:如何使用Parallel :: ForkManager管道?
use Parallel::ForkManager;
my @array;
my $pm=new Parallel::ForkManager(3);
for((1..5)){
$pm->start and next;
print "child: ".$_."\n";
push(@array,$_); # what do I do here to put it into the parent's @array????
$pm->finish;
}
$pm->wait_all_children;
print "parent: ".$_."\n" for @array;
不错;完成的第二个参数是新的,而不是在我已经安装的旧版本中,但它很有意义,这个功能被合并到P :: FM本身中。 – ysth
我完全反映了ysth的情绪。有人在我最近看到的部分代码中使用了第二个参数,但我并不知道P :: FM本身正在处理它。上次我看着P :: FM时,它不存在。谢谢! – ikegami
真正有用的答案 - 谢谢。值得注意的是,run_on_finish中sub的第5个参数总是包含数据结构。我的($ pid,$ exit_code,$ ident,$ exit_signal,$ core_dump,$ data_structure_reference)= @_; – hardingnj