in reply to In the BEGINing there were no forks?

perlfork explains the caveats of fork() with BEGIN blocks.

<snip>
BEGIN blocks The fork() emulation will not work entirely correctly when called from within a BEGIN block. The forked copy will run the contents of the BEGIN block, but will not continue parsing the source stream after the BEGIN block. This limitation arises from fundamental technical difficulties in cloning and restarting the stacks used by the Perl parser in the middle of a parse.
</snip>

Replies are listed 'Best First'.
Re^2: In the BEGINing there were no forks?
by Anonymous Monk on Feb 14, 2005 at 20:10 UTC
    Yes. I know. Hence my question. I could use some stupid method of a system call to call my perl code again, and work out a crazy way to make sure that that only happens once, in the BEGIN block. But that is ugly. Is there a cunning nice way?
      Ahh, I see. My apologies

      Well, for the child, you're pretty much hosed outside the begin block, so maybe split up the BEGIN block into one file and the logic into another?

      BEGIN { $pid = fork(); require "logic.pl" if $pid; } require "logic.pl";


      Dunno, just a thought. Good luck with it