in reply to Please Explain the Parallel::ForkManager Idiom my $pid = $pm->start and next;

When $pm->start returns, two processes exist, the parent and the child. In the parent process, $pm->start returns the process id which is a non-zero value (ie true) and thus and executes the next command. In the child process, $pm->start returns 0 (ie false) and thus and short-circuits (if the first argument is false already, and returns false always without evaluating the second argument). This way, next is not executed but the remaining body of the loop.

So, you are correct, next is skipped (in the child) and not skipped (in the parent).

Replies are listed 'Best First'.
Re^2: Please Explain the Parallel::ForkManager Idiom my $pid = $pm->start and next;
by Jim (Curate) on Feb 04, 2014 at 08:02 UTC

    Thanks. I still don't get it. I'm having a more profound problem than just not understanding the idiom. I don't understand the ubiquitous expressions I read over and over again in the documentation and in PerlMonks tutorials and posts:  "…in the parent process…", "…in the child process…", etc. These make no sense to me. And running the example scripts and observing their behavior isn't helping, but instead making it worse because the behavior is utterly counterintuitive to me. The particular example code I'm running from the module's perldoc page has sleep()s in it that I know the code is reaching, but are never actually happening. There's never a pause in the execution of the program. It blows right past the sleep()s.

      Mh, imho the example with the callbacks is very nice and instructive. Did you run it and take a look at watched top during execution?

      Regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

        Yep. That's the script I'm running and studying, and the one I mentioned is utterly confounding me.

        Jim