use IPC::Shareable;
use Data::Dump qw(ddx);
$| = 1;
# Setup shared array reference "my_var"
my $id = 'my_special_name';
my %options = (create => 'yes', exclusive => 0, mode => 0644, destroy => 'yes');
my $my_var;
tie $my_var, 'IPC::Shareable', $id, { %options } or die "tie failed: $!\n";
$my_var = [0..10];
system('./child.pl &');
until ($my_var->[-1] == 999) {
my $num = int(rand()*100);
push @$my_var, $num;
ddx [ @$my_var ];
sleep 2;
};
print "Leaving adult.pl..\n";
####
use IPC::Shareable;
use Data::Dump qw(ddx);
$| = 1;
my $id = 'my_special_name';
my %options = (create => 0, exclusive => 0, mode => 0644, destroy => 0);
my $my_var;
tie $my_var, 'IPC::Shareable', $id, { %options } or die "tie failed: $!\n";
for (0..3) {
my $num = int(rand()*100);
push @$my_var, $num;
ddx [ @$my_var ];
sleep 2;
}
push @$my_var, 999;
print "Leaving child.pl..\n";
####
# adult.pl:20: [0 .. 10, 16]
# child.pl:16: [0 .. 10, 16, 72]
# adult.pl:20: [0 .. 10, 16, 72, 52]
# child.pl:16: [0 .. 10, 16, 72, 52, 17]
# adult.pl:20: [0 .. 10, 16, 72, 52, 17, 66]
# child.pl:16: [0 .. 10, 16, 72, 52, 17, 66, 96]
# adult.pl:20: [0 .. 10, 16, 72, 52, 17, 66, 96, 92]
# child.pl:16: [0 .. 10, 16, 72, 52, 17, 66, 96, 92, 88]
# adult.pl:20: [0 .. 10, 16, 72, 52, 17, 66, 96, 92, 88, 56]
Leaving child.pl..
Leaving adult.pl..