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

Multidimensional array / Passing an array to a sub

Thread Next
Martin Tournoij
July 30, 2006 00:22
Multidimensional array / Passing an array to a sub
Message ID:
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About