in reply to passing arrays to subroutines
A subroutine gets it's arguments as an array (@_), so if you do
Within some_sub, @_ will equal the contents of @array.my @array = (1,2,3,4,5); some_sub(@array);
However, you probably want to pass the array into the subroutine by reference (see perlref for more):
In that case, the first element of @_, the argument list to some_sub, will be a reference to @array.my @array = (1,2,3,4,5); some_sub( \@array );
If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
That way everyone learns.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: passing arrays to subroutines
by Anonymous Monk on Apr 13, 2011 at 14:22 UTC |
In Section
Seekers of Perl Wisdom