[VPM] array refs driving me nuts

Darren Duncan darren at DarrenDuncan.net
Thu May 20 14:44:15 CDT 2004


At 12:05 PM -0700 5/20/04, Carl B. Constantine wrote:
>WARNING WILL ROBINSON --- NEWBIE QUESTION
>
>I'm trying to print out the value of an array reference. The reference
>is passed into a function as \@array.
>
>Now in that function I pass out $arrayRef to another function. It's in
>this final function I want to print out the value(s) of the array.
>
>I've tried @$arrayRef, $$arrayRef, $@$arrayRef, @$arrayRef[0] all to no
>avail.
>
>What did I miss?

Assuming you want the original values, then "@{$arrayRef}" can be 
used in exactly the same way as "@array"; "$arrayRef->[0]" or 
"${$arrayRef}[0]" (the first one is what I use) can be used the same 
way as "$array[0]".

Note that Perl does have short hand syntax which allows you to leave 
out the {} when dereferencing the whole array, put putting it in 
ensures that scoping is correct (much like putting parenthesis around 
an expression for grouping), and keeping the {} makes the code more 
self-documenting.

-- Darren Duncan



More information about the Victoria-pm mailing list