in reply to sharing array of arrays between threads

One of your mistakes is that you first create $X which looks like it's a reference to array, but then try to print @X[1], which is an element of @X which is different to $X. See this example:
$ perl -d -e 1 DB<1> $X = [ 1 .. 10 ]; # create a reference to an anonymous array DB<2> x $X # print the array by its reference 0 ARRAY(0x9a45510) 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 DB<3> @X = ( 2 .. 20 ); # create an array DB<4> x @X # display the array 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 16 18 17 19 18 20 DB<5> x @X[1] # display an element of the array 0 3 DB<6> x $X->[1] # display an element of the anonymous array by its r +eference 0 2
See perlreftut for more information.
Sorry if my advice was wrong.

Replies are listed 'Best First'.
Re^2: sharing array of arrays between threads
by bebe (Novice) on Aug 10, 2012 at 23:32 UTC

    thank you so much for your help....
    I've also tried the following... but I still have no luck getting this to work


    my @X : shared;
    my $var = &share([]);
    for (my $i=0; $i< 222; $i++){
    $X[$i] = $var;
    }


    sub abc {
    my $Var2;
    .... Here the string in $Var2 gets updated everytime abc is called
    push(@{X[$i]}, $Var2);
    }


    thank you so much!!!

      How exactly this doesn't work? Did you try using Data::Dumper to print your variables inside the threads?
      Sorry if my advice was wrong.