[VPM] array refs driving me nuts

Carl B. Constantine cconstan at csc.UVic.CA
Thu May 20 15:49:18 CDT 2004


*On Thu May 20, 2004 at 12:21:26PM -0700, Peter Scott (Peter at PSDT.com) wrote:
> 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.

Correct.

> >I've tried @$arrayRef, $$arrayRef, $@$arrayRef, @$arrayRef[0] all to no
> >avail.
> 
> That first one should work, or it's not an arrayref.

That's what I thought.


> 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

Well, what happens when I do it:

@array = somefuncreturningarrayvalues();

foo(\@array)

sub foo {
    my $arrayRef = @_;

    bar($arrayRef);
}

sub bar {
  my $array = @_;

  print "Array Values: @$array\n";
}
ARRAY(HEXADDRESS)

-- 
Carl B. Constantine         University of Victoria
Programmer Analyst          http://www.csc.uvic.ca
UNIX System Administrator   Victoria, BC, Canada
cconstan at csc.uvic.ca        ELW B206, 721-8766



More information about the Victoria-pm mailing list