Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^6: enumerating values for slopes

by farang (Chaplain)
on Sep 24, 2014 at 02:07 UTC ( #1101736=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1101736]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2023-02-01 15:29 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (10 votes). Check out past polls.