in reply to Creating a hash within a fork

Variables are not shared between forks. See forks::shared.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Creating a hash within a fork
by edimusrex (Monk) on Jun 04, 2015 at 17:10 UTC
    Thanks for the reply, I will look into that.

      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.