in reply to Re^5: forked::shared with hashes?
in thread forked::shared with hashes?

I thought the author might mean this: ...

Okay. I'm not sure that matches the OPs description: It turns out the problem has to do with the restriction that you should share scalar variables, not complex structures like hashes., but given that he is obviously very confused, and still not using strict, understandable :)

You also said; "No, for me, it worked with a hash as well.". Does that work bidirectionally? Ie. Can the parent see changes made to the hash by the child?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^7: forked::shared with hashes?
by choroba (Cardinal) on Apr 04, 2011 at 06:42 UTC
    Does that work bidirectionally?
    Yes, it does.

    UPDATE: Sample code:

    use warnings; use strict; use forks; use forks::shared; my %GLOBALHASH : shared; share (%GLOBALHASH); my $pid = fork (); if (!$pid) { # child $GLOBALHASH{OILPRICE} = 100; sleep 1; print "Gold price from the parent: $GLOBALHASH{GOLDPRICE}\n"; exit 0; } elsif ($pid) { # daddy $GLOBALHASH{GOLDPRICE} = 200; sleep 2; print "Global Oils Price is now: " . $GLOBALHASH{OILPRICE} . " dol +lars\n"; }
    Output:
    Gold price from the parent: 200 Global Oils Price is now: 100 dollars