bebe has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm soooo stuck please help me. I've been trying to share this array forever but it does not work for me. :(
I need to make this work but I have to use "share" here, I can not simply return the variable. any idea how I can fix this?
use threads::shared; use strict; use warnings; use Data::Dumper; my $tmp=meow(); #my @state : shared; #if I use this line instead I get this "inva +lid value for shared scalar. (since state is an array of arrays)" my @state = &share([]); for (my $i = 0;$i <6 ; ++$i) { my $row = &share([]); @{$state[$i]} = $row; } print Dumper(@state); sub meow { my $i = 0; my $j = 1; my @p = ("grey" , "striped" , "purrr", "cutest_kitty" , "meowing_kitty", "the_lord_of_the_cats"); my @k = ("smart_kitty" , "striped_sweety" , "purrr", "meowing_poes" , "social_kitty", "the_lord_of_the_poezen"); for (my $f=0; $f<6 ; $f++) { push(@{$state[$i]}, $p[$f]); push(@{$state[$j]}, $k[$f]); }
and here is my output when I run this
~/my_perl_test> perl sharingpoes2.pl $VAR1 = [ [] ]; $VAR2 = [ [] ]; $VAR3 = [ [] ]; $VAR4 = [ [] ]; $VAR5 = [ [] ]; $VAR6 = [ [] ];
I really really appreciate all your help.
thanks a lot
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sharing array please help
by BrowserUk (Patriarch) on Aug 15, 2012 at 00:06 UTC | |
|
Re: sharing array please help
by aitap (Curate) on Aug 15, 2012 at 06:48 UTC | |
|
Re: sharing array please help
by BrowserUk (Patriarch) on Aug 14, 2012 at 23:09 UTC | |
by bebe (Novice) on Aug 14, 2012 at 23:17 UTC | |
by BrowserUk (Patriarch) on Aug 14, 2012 at 23:31 UTC | |
by bebe (Novice) on Aug 14, 2012 at 23:36 UTC | |
by bebe (Novice) on Aug 14, 2012 at 23:49 UTC | |
|
Re: sharing array please help
by kcott (Archbishop) on Aug 15, 2012 at 19:51 UTC |