Hello,

---------- CODE ----------

#!/usr/bin/env perl

use strict;
use warnings;
use Parallel::ForkManager;

# Parallel::ForkManager
my $pfm = Parallel::ForkManager->new(5);

my %hash;
for my $num ( qw/ 1 2 3 4 5 1 / ) {
    $pfm->start and next;
    $hash{$num}++;
    $pfm->finish;
}
$pfm->wait_all_children;

# doesn't print because %hash is undef
print "$_ => $hash{$_}\n" for sort keys %hash;

print "hash is undef\n" unless %hash;

----------- END -----------

I want to do work on all elements of an array simultaneously.
I tried Parallel::ForkManager. It works well when you don't need to update
global value like downloading
multiple files at the same time. I want something like above that forks
while updating global values.
Are threads/fork what I am looking for?

Any help would be *appreciated.*

Reply via email to