Bloehdian has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I wanted to share an array between to processes created by fork(), but the following code is broken and I have no clue why:
It yields:use strict; use diagnostics; use IPC::Shareable; use POSIX ":sys_wait_h"; my @data; my %options = ( create => 1, exclusive => 0, mode => 0644, destroy => 1, ); my $pid; my $item; if ( ! defined ( $pid = fork() ) ) { die( "Cannot fork!: $!" ) } elsif ( $pid == 0 ) { # Child #tie( @data, 'IPC::Shareable', 'glue', \%options ); sleep 1; for ( my $i=1; $i <= 10; $i++ ) { $item = shift( @data ); if ( ! defined $item ) { $item = '' } print "Child: $item\n"; } } else { # Parent tie( @data, 'IPC::Shareable', 'glue', \%options ); for ( my $i=1; $i <= 10; $i++ ) { push( @data, $i ); print "Parent: @data\n"; } waitpid( $pid, WNOHANG ); }
Not an ARRAY reference at /usr/local/share/perl/5.20.2/IPC/Shareable.p +m line 362 (#1) (F) Perl was trying to evaluate a reference to an array value, but + found a reference to something else instead. You can use the ref() func +tion to find out what kind of ref it really was. See perlref. Uncaught exception from user code: Not an ARRAY reference at /usr/local/share/perl/5.20.2/IPC/Sha +reable.pm line 362. IPC::Shareable::PUSH(IPC::Shareable=HASH(0x2604088), 1) called + at test_2.pl line 45 xyz@v32470:~/trans_gpsd/bin$ Child: Child: Child: Child: Child: Child: Child: Child: Child: Child:
Any idea?
Cheers
Bloehdian
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IPC:Shareable: Not an array reference
by marioroy (Prior) on Oct 11, 2016 at 02:47 UTC | |
by marioroy (Prior) on Oct 11, 2016 at 03:02 UTC | |
by Bloehdian (Beadle) on Oct 11, 2016 at 03:54 UTC | |
by marioroy (Prior) on Oct 11, 2016 at 06:52 UTC | |
by marioroy (Prior) on Nov 01, 2016 at 22:19 UTC | |
by Marshall (Canon) on Oct 11, 2016 at 06:17 UTC | |
by marioroy (Prior) on Oct 11, 2016 at 07:15 UTC | |
|
Re: IPC:Shareable: Not an array reference
by marioroy (Prior) on Oct 11, 2016 at 09:15 UTC | |
by marioroy (Prior) on Oct 11, 2016 at 12:15 UTC | |
|
Re: IPC:Shareable: Not an array reference
by Marshall (Canon) on Oct 11, 2016 at 00:28 UTC |