Monks, I am attempting to allow a child to update a hash value that the parent can later reference. This appears possible using forks::shared. Here is a trivial example of a parent and child sharing an integer variable.

use forks; use forks::shared; my $GLOBALPRICE : shared; share ($GLOBALPRICE); my $pid = fork (); if (!$pid) { # child $GLOBALPRICE = 100; exit 0; } elsif ($pid) { # daddy sleep (2); print "Global Oils Price is now: " . $GLOBALPRICE . " dollars\n"; }

However, if I turn the shared variable into a hash reference, the parent will not see the child's change. For example:

use forks; use forks::shared; my %GLOBALHASH : shared; share (%GLOBALHASH); my $pid = fork (); if (!$pid) { # child $GLOBALHASH->{OILPRICE} = 100; exit 0; } elsif ($pid) { # daddy sleep (2); print "Global Oils Price is now: " . $GLOBALHASH->{OILPRICE} . " d +ollars\n"; }
In this second case, the parent cannot see the OILPRICE key. Could someone explain how to modify the hash example so that the parent and child can properly share a hash?

In reply to forked::shared with hashes? by GriffinP

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.