develooper Front page | perl.beginners | Postings from July 2006

Multidimensional array / Passing an array to a sub

Thread Next
From:
Martin Tournoij
Date:
July 30, 2006 00:22
Subject:
Multidimensional array / Passing an array to a sub
Message ID:
op.tdhk7er3oycwod@carpet
I'm currently massivly confused by multidimensional arrays and passing  
arrays to subs.

Why is it that @_[1] isn't properly copied to @a?

I'm not sure what exactly I'm doing wrong here, probably something simple,  
but I can't find anything that works in the manpages or on the site...

Music($var1, \@array);

sub Music
{
   print $_[1][1];  # works
   my @a = @_[1] # Gives warning, should be written as $_[1]

   print $a[1]; # Outputs ARRAY(#memaddr)
   print $a[1][1]; # Works

   for (@a)
   {
     print;  # Outputs ARRAY(#memaddr)
   }

   for (@_[1])
   {
     print; # Also outputs ARRAY(#memaddr)
   }
}

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About