http://qs1969.pair.com?node_id=1101736


in reply to Re^5: enumerating values for slopes
in thread enumerating values for slopes

You need to push on @AoA a reference to @vector:
my @vector = (4.3125, 0.4375); push @AoA, \@vector; @vector = (4.375, 0.375); push @AoA, \@vector;
That way is buggy, though, as the redefinition of @vector will clobber the first pushed array element. This is explained under COMMON MISTAKES in perldsc, "taking a reference to the same memory location repeatedly".

So both lines above should instead use a square bracket reference.

push @AoA, [ @vector ];

Replies are listed 'Best First'.
Re^7: enumerating values for slopes
by Laurent_R (Canon) on Sep 24, 2014 at 06:59 UTC
    You are right, it's a mistake to push references to the same array without declaring it anew. I have been bitten by that a couple of times, I should know better. That's why I am actually almost always using the second method using the [] anonymous array reference constructor.