in reply to forked::shared with hashes?

Use strict! Do not mistake $GLOBALHASH for %GLOBALHASH.

Replies are listed 'Best First'.
Re^2: forked::shared with hashes?
by GriffinP (Initiate) on Apr 02, 2011 at 00:01 UTC

    It turns out the problem has to do with the restriction that you should share scalar variables, not complex structures like hashes. So the parent can see the child's hash modifications if you do something like this:

    use forks; use forks::shared; my %GLOBALHASH : shared; my %hashref : shared; $hashref = \%GLOBALHASH; $child = fork (); if (!$child) { # child $hashref->{OILPRICE} = 100; exit 0; } elsif ($child) { # daddy sleep (2); print "Global Oils Price is now: " . $hashref->{OILPRICE} . " doll +ars\n"; }

    However, I've not been able to get this to work with hashes of hashes.

      No, for me, it worked with a hash as well. The restriction applies to threads::shared, not forks::shared.
        The restriction applies to threads::shared,

        Could you:

        1. explain "the restriction"
        2. either show where that restriction is documented; or code to demonstrate it?

        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.