in reply to How do i create array of arrays
I hope that helps.my @array = ( 1..3 ); my $arrayRef = \@array; my @arrayOfArrays = ($arrayRef); print $arrayOfArrays[0]->[1];
{Editor note by davido: This approach is risky. For one thing, if @array ever changes, its changes will affect @arrayOfArrays. Thus, if you build up an array of arrays using this method inside of a loop, you could end up with multiple instances of the same @array, rather than multiple distinct and unique arrays as the contents of the @arrayOfArrays. Using my within the loop will create a new @array each time through, but better to be explicit about it rather than relying on lexical scoping which can confuse the reader later on.
Changing the second line to:
will solve the potential problem.
|
|---|