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
 
----- Original Message -----
Sent: Friday, September 15, 2006 7:21 AM
Subject: RE: Help with array syntax?


> @row = shift @cnxns;
> <access $a, $b and $c out of @row>
 
  The normal (i.e. Perlish elegant) way to deal with references is to
use a dollar$variable that you dereference later when needed.  (I also
find that Hungarian notation helps programmers and maintainers immensely
with this sort of thing.)

# @ara is an Array of References to Arrays
my $ra = shift @ara;
# $ra is a Reference to an Array
# Now access $ra->[0], $ra->[1], etc.

 - - Martin
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to