cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
The docs say you can use this method to return a data structure, but they refer to the thing returned as a string. Is $string really a string or is it an object?use strict; use feature ':5.10'; use Parallel::ForkManager; our $pm = Parallel::ForkManager->new(8); $pm -> run_on_finish ( # called BEFORE the first call to start() sub { my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_ +structure_reference) = @_; # retrieve data structure from child if (defined($data_structure_reference)) { # children are not +forced to send anything my $string = ${$data_structure_reference}; # child passe +d a string reference if ($string) { #how to process $string? }; } else { # problems occurring during storage or retrieval will +throw a warning say qq|No message received from child process $pid!|; } } ); LOOP: foreach my $instance (0..100) { $pm->start and next LOOP; # do the fork my $data; foreach my $i (0..50) { push(@$data,int(rand(10)); } $pm->finish(0,\$data); # exit the child process } $pm->wait_all_children;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parallel:ForkManager how to pass back a list
by davido (Cardinal) on Apr 05, 2024 at 18:04 UTC | |
Re: Parallel:ForkManager how to pass back a list
by marioroy (Prior) on Apr 06, 2024 at 05:41 UTC | |
Re: Parallel:ForkManager how to pass back a list
by talexb (Chancellor) on Apr 06, 2024 at 15:27 UTC |