for($i=0; $i <$data ; $i++){ some code ...... ...... ....... for($j=0;$j <= $#$data_2; $j++){ ............... ........... } push @new_array, $data; #I want to store this @new_array into hash based on $i as a key. I don't want to use the reference because for every iteration @new_array contain new array value. I want some thing like that my %join_array[$i] = @new_array; } output should be 0->{o,1,2,3} 1->{2,3,5} 2-> {5,7,8} some thing like that. Thanks

Laurent is right about your lack of understanding. Please read the FAQ

Code

perldoc -f "How do I declare/create a structure"

Be sure to also read the documents that it refers to (perlref and perldsc). I also suggest reading perllol. If you still cannot understand well enough to answer your original question, post questions about the documents here. Good Luck, Bill

It's not entirely clear to me, what you want to achieve (and what is an *unknown* array, as opposed to a *known* one), but this piece of code has several problems:

1. The expression %join_array[$i] doesn't make sense. Do you perhaps mean $join_array{$i} ?

2. You can't localize with 'my' only one element of an array or hash. You can only localize the whole array or hash.

3. In your example (using humans and faeries), you show that a hash element should have as value the *reference* of an array, which is the correct approach. However, @new_array is not a array reference, but an array. To turn an array into a reference to the array, you have to use the \ operator, i.e.

Although this is valid code (assuming that an array @data is defined), It does not answer your original question. I do not think that you will like what it does. The values of all the elements of @join_array will be exactly the same (a reference to the array @data). It does not make any difference if the values in the @data array change between the times that you make these references.

To solve your original problem, your last statement should be:

Code

$join_array[$i] = [@new_array];

The square brackets create a new anonymous array, populate it with the current values from @new_array, and return a reference to the new array. That reference is then stored in $join_array[$i]. Good Luck, Bill

Now i am trying to store the $join_array[$i] array into @array_index by using $tmp array value as an index. For example $join_array[0]= {AA,BB,CC,DD} and @$tmp{2,1,0,3}# It act as index No. Then @array_index= {CC,BB,AA,DD}

Code

$join_array[$i] = [@new_array]; $tmp = $per[$j]->combination($perm->[$j]); ............ .................. #I write this code for doing that but I am not sure about [@$tmp[$k]] statement, am i doing right here?