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:
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?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 reply to forked::shared with hashes? by GriffinP
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |