|
Hello all,
Also, a practical way to do what you want,
is:
# @references is an
array of references to arrays
my @singleArray = @{shift
@references};
Now, @singleArray is just a typical
array.
# And, to push it
back as an array reference:
push @references,
[EMAIL PROTECTED]; # or...
push @references,
[EMAIL PROTECTED]; References are tricky. The first example of
pushing, is pushing a real and total reference to @singleArray, meaning that if
you later modify the first array in @references, ALSO @singleArray will be
modified (if accessed by reference), since it's a real reference to that array.
In the second example of pushing, you would be CREATING a new array reference
that contains what @singleArray contains, but a later modification to the first
element of @references, will *not* alter @singleArray. This is an
example:
my @arr1 = (1, 2, 3);
my @arr2 = (4, 5, 6); # Storing references to
@arr1 and @arr2
my @references = ([EMAIL PROTECTED],
[EMAIL PROTECTED]);
@{$references[0]} = ('a', 'b', 'c'); # Here i'm accesing the real reference to @arr1 and changing
it
$references[1] = [('d', 'e', 'f')]; # Here i'm just replacing the reference to @arr2 by a new arr reference print join ', ', @arr1; # Will print the new values a, b, c print join ', ', @arr2; # Will print the original values 4, 5, 6 (since i replaced the reference, @arr2 didn't change) # And, also, if i
modify @arr1, the contents of $references[0] will change too, but if i modify
@arr2, $references[1] won't change, since it's not referenced to @arr2
anymore.
I hope it helps.
Paco Zarabozo
|
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
