[VPM] array refs driving me nuts

Peter Scott Peter at PSDT.com
Thu May 20 14:21:26 CDT 2004


At 12:05 PM 5/20/2004, Carl B. Constantine wrote:
>WARNING WILL ROBINSON --- NEWBIE QUESTION
>
>I'm trying to print out the value of an array reference.

ITYM you want the values of the array referred to by an arrayref.  The 
value of an arrayref is useless.

>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.

That first one should work, or it's not an arrayref.

This is what happens when I do what you describe:

% perl -Mstrict -wl
my @array = qw(dog cat bird aardvark);
foo(\@array);
sub foo {
   my $arg = shift;
   bar($arg);
}
sub bar {
   my $arrayref = shift;
   print "@$arrayref";
}
^D
dog cat bird aardvark

-- 
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
*** New! *** http://www.perlmedic.com/




More information about the Victoria-pm mailing list