http://www.perlmonks.org?node_id=1022127


in reply to Perl fork childs with variables

Hello Stefan!

The thing with a fork()'d model is that the operating system is creating two additional and separate processes. While they initially have (nearly) the same state as the parent, they are in fact separate, and any changes to memory (i.e., variables) in one will have no effect on the other processes, just as you would expect with any other distinct process.

All is not lost: you will need to use some form of inter-process communication (IPC) to allow your processes to communicate their results to the parent. If you are in a POSIX environment (likely, if you are using fork()), you might have a look at IPC::SysV and IPC::Msg for a start, and do some searching on http://www.cpan.org for other IPC modules best suited to what you need to do.

Finally, is there a special reason you actually need a fork()'d model in the first place? Can you use threads instead? Perl's threads implementation makes shared variables and semaphores between threads very easy.