in reply to Re: Multi-dimensional arrays...
in thread Multi-dimensional arrays...

Wouldn't this solution make all elements of the double array point to the same reference, which means the same array?

What if they need to each have there own separate array?

Replies are listed 'Best First'.
Re^3: Multi-dimensional arrays...
by johngg (Canon) on May 31, 2009 at 19:12 UTC

    No, the my @record = ...; inside the inner loop creates a new lexically scoped array each iteration. Consider the following code.

    $ perl -Mstrict -wle ' > my @arr; > foreach my $iter ( 1 .. 3 ) > { > my @rec = map { $_ * $iter } ( 1, 2, 3 ); > push @arr, \ @rec; > } > print qq{$_: @$_} for @arr;' ARRAY(0x22aa8): 1 2 3 ARRAY(0x22b14): 2 4 6 ARRAY(0x22b80): 3 6 9 $

    Note how the references are different for each element of @arr and the contents reflect the value of $iter each time through the loop.

    I hope this is helpful.

    Cheers,

    JohnGG

      Thank you for the further clarification, excuse my ignorance. And many thanks :D