⭐ in reply to How do I access an array for which I only have a reference?
A really good book to get is O'Reilly's Advanced Perl Programming if you are going to get into this sort of thing. But here is my brief explanation.
Let's say you have an array reference...
Now the question is, what exactly is in $r_array? It's sort of similar to the concept of pointers in C: a reference contains the address of where the data is actually located in memory. If you print $r_array directly, you get something funky looking like ARRAY(0xc70858), which is clearly not the data stored in the array. So think about your reference this way: it's just a sign saying where the data really is.my $r_array = [ 'inky', 'blinky', 'blu' ];
To get at the data where it really is, you have to dereference the reference, using the following syntax:
You could use it in code, like this:@{ $r_array }
Now, as a shorthand, Perl lets you omit the curly braces (for reference variables only):for ( @{ $r_array } ) { print "$_\n"; }
for ( @$r_array )
|
|---|