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
In reply to IPC:Shareable: Not an array reference by Bloehdian
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |