in reply to Re: Creating a hash within a fork
in thread Creating a hash within a fork

Thanks for the reply, I will look into that.

Replies are listed 'Best First'.
Re^3: Creating a hash within a fork
by sierpinski (Chaplain) on Jun 04, 2015 at 17:40 UTC

    Not sure if this is a big help to you, but you can use the return code of the child processes to communicate with the parent process. I did that in this case:

    $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; $connected_server_count += $exit_code; $progress = ($count / $total_server_count) * 100; printf "Progress: %4.1f\%\r",$progress; $count++; } );
    Example of a bad (0) return:
    $pm->finish(0); # Couldn't connect to this one, skip to next server in + main loop
    Example of a good (1) return:
    # Close ssh connection to this server $ssh->close(); $pm->finish(1);

    The point being that $count kept track of how many servers were processed ($connected_server_count is used elsewhere) but it based that count on the return code. In this code, a server returned 0 if it could not connect, but returned 1 if it could, so I just summed those values. I've not played around with it, but I assume you can map out any numeric code to suit your purposes, perhaps the number of days, etc.