in reply to Re^2: appending and array into last element of an array?
in thread appending and array into last element of an array?
OK. that sounds good so far, but if I'm doing this in a looping context, and the next time around the loop, the values of @arrayB change, won't that change all of the references as well?
It depends on where @arrayB is declared.
my @arrayA; my @arrayB; while (...) { @arrayB = ...; push(@arrayA, \@arrayB); # XXX }
my @arrayA; my @arrayB; while (...) { @arrayB = ...; push(@arrayA, [ @arrayB ]); # Ok }
my @arrayA; while (...) { my @arrayB = ...; push(@arrayA, \@arrayB); # Ok }
my @arrayA; while (...) { my @arrayB = ...; push(@arrayA, [ @arrayB ]); # Needlessly creating 3rd array. }
Also, how could I save the anon array in your second example?
What does "save" mean? Copy? You already have a copy of the array in @arrayB.
|
|---|