| [reply] [d/l] |
@array2 = @{$arrayref};
This will copy the referenced array into a new array. Usually when we speak of dereferencing, we mean using a reference directly (e.g. $arrayref->[2]). That aside, this will give you a "real" array from a reference, with the caveat that it will be making a copy, and might potentially be very expensive. I really recommend just using the reference directly. | [reply] [d/l] [select] |
Thanks for the clarification on the terminology.
Is there a term for what I am trying to do other than stupid, unwise, costly, etc?
| [reply] |
You can simplify the $arrayref creation:
my $arrayref = [1,2,3,4,5,6,7,8]; # Note: SQUARE brackets
Yes, you can copy arrays as you have done, and yes, it will work for AoA and AoH, but, as indicated by other posters, this is not very efficient. Why not use and pass the Array ref itself ? The only down-side is the de-referencing syntax:
my $third_element = $arrayref->[2];
but you get accustomed to that pretty soon.
Once you get past the reference-passing phobia, your programs become cleaner and more efficient.
perldoc perlref is your friend. | [reply] [d/l] [select] |