What do you want to do with it? Just what you have (without the &) is fine:
my @updated = sortArray (@array); ... sub sortArray { my @copy = @_; return sort @copy; }
if you want to edit the array then passing it by reference may be what you want:
editArray (\@array); ... sub editArray { my $arrayRef = shift; push @$arrayRef, 'new array element'; }
There are other variations and the choice of method mostly depends on things like how big the array is and readability of the code. In particular, if you pass an array by reference that may be a strong hint that it will be updated by the subroutine. Passing an array using (@array) is a strong hint that the contents of the array won't be affected by the subroutine.
In reply to Re: HOW Can I pass the array into my subroutine?
by GrandFather
in thread HOW Can I pass the array into my subroutine?
by snowsky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |