Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: Global Variables Not Updated in Child Process

by afoken (Abbot)
on Nov 21, 2012 at 18:13 UTC ( #1004980=note: print w/replies, xml ) Need Help??

in reply to Re^2: Global Variables Not Updated in Child Process
in thread Global Variables Not Updated in Child Process

My Prime focus is not forking but process some thing in a child process and get the values updated in parent.

So you want your son to learn French and your daugther to learn German, and you expect that you automatically speak both French and German as soon as both have finished learning. Does that work in real life? Nope. And it also won't work with fork()ed processes.

Please read fork-exec, fork, and perhaps also exec.

Generally, processes can't update other processes data. You need some kind of inter-process communication, or shared memory. Shared memory won't work well with Perl, because perl tends to move data around when its size changes. See perlipc for details on both ways.

Another option, with its own set of traps, is using threads. Threads give you lightweight "processes" inside a single process, and threads can actually share variables. See perlthrtut for details. Of course, this works only if all external programs you are using now are merged into a single big program (possibly by moving each program into a single module).


Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^4: Global Variables Not Updated in Child Process
by Anonymous Monk on Nov 21, 2012 at 19:34 UTC
    Dear afoken, the natural analogy is the parent process getting pregnant because the child process had sax

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004980]
[Corion]: Hmm. I think overnight I decided on simplifying some code. I have plugin classes that do data import (.csv, .yml, .json) and for that create objects on which then ->load() is called. But YAML::XS doesn't have an object, so I wrote my own wrapper.
[Corion]: This evening, I'll kill that wrapper again, and just call LoadFile() in the plugin class directly instead of creating a go-between object for no real gain.
[Corion]: Writing these import plugins was really nice though - in about 2 hours, I had imports for CSV, YAML and JSON, and adding XLS(X), SQLite (or DBI) data sources is also trivial. I'm idly wondering about separating the plugin into transport+parser, so ...
[Corion]: ... http:// URLs could be retrieved and then parsed, but I think that that would be overkill for a toy static site generator ;)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2018-05-22 11:04 GMT
Find Nodes?
    Voting Booth?