ajeet@perl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl monks

I am using forks module from CPAN, I get error when i write

$queue[0] = [1,2,3,4];

where, i delared $queue as shared variable, actually i wanted to store 1,2,3,4 in second dimension of array. It gives me arror as..

Invalid value for shared scalar at ./emsNBIAlarmListener.pl line 107 at /usr/local/lib/perl5/site_perl/5.8.8/sun4-solaris/forks/shared.pm +line 563 threads::shared::STORE('threads::shared=HASH(0x872e10)', 0, 'A +RRAY(0x435190)') called at ./emsNBIAlarmListener.pl line 107

But,When i write...

$queue[0] = \[1,2,3,4];

I get no error, but i dont know how to access the values now in first or second dimension....

Please Help me ...

Thank You Monks..

Replies are listed 'Best First'.
Re: sharing array references through fork::shared
by cdarke (Prior) on Apr 10, 2010 at 16:14 UTC
    $queue[0] contains a reference to a reference to an anonymous array. This will illustrate:
    my @queue; $queue[0] = \[1,2,3,4]; print "$queue[0]\n"; print "${$queue[0]}}\n"; print "@{${$queue[0]}}\n"; my $ref = ${$queue[0]}; print "$ref->[1]\n";
    Gives:
    REF(0x3a09c) ARRAY(0x3a1bc)} 1 2 3 4 2
    Although, judging from the doc for threads::shared you might still have issues.
      Thank you cdarke.... resolved my problem...also in thread::shared..