in reply to Re: Parallel::ForkManager problem
in thread Parallel::ForkManager problem

$result{$query} = ! $? can you explain this! Please

Replies are listed 'Best First'.
Re^3: Parallel::ForkManager problem
by Limbic~Region (Chancellor) on Mar 28, 2006 at 15:50 UTC
    Murcia,
    If you look in perlvar, you will see that $? is the status returned by the last closed pipe. The ! is a way to booleanize it. If it has a non-zero value, it becomes 0 and if it had a 0 value, it becomes 1.

    Cheers - L~R

      If you look in perlvar, you will see that $? is the status returned by the last closed pipe.

      well, no, you have stoped reading too soon:

      $? The status returned by the last pipe close, backtick (``) command, successful call to wait() or waitpid(), or from the system() operator.
      in my code, it is set to the exit code of the child by waitpid.

      It is negated because by convention, exit code 0 means success and any other value failure. Also because this way I don't have to split $? into the signal part and the exit code:

      $signal = $? & 255; $exit_code = $? >> 8;
        salva,
        There were some missing ... as I didn't want to copy and paste the whole entry. My intention was to get Murcia reading for themself.

        Cheers - L~R

      But the problem of scope remains with your module, or?
        yes, as for any fork based solution, after the fork, changes on the child variables do not propagate to the parent because they live in different processes and memory is not shared.

        My solution is only valid if all you need to pass is a single integer value. For other cases you can use threads, some kind of IPC or external storage to pass data between processes.

        For instance, if what you want to share is a hash, you can use some of the DB modules to store the hash on disk and share it between all the processes, though you will need to use some module that handles concurrency properly or else do it yourself locking the shared file before accessing the on-disk hash.