in reply to HOW Can I pass the array into my subroutine?
I'm a fan of Params::Validate. It's a great module that help you deal with lack of parameter checking in Perl.
This is how you declare your module with it:
use Params::Validate ':all'; sub sortArray { my ($unsorted) = validate_pos(@_, { type => ARRAYREF }); my @sorted = sort @{ $unsorted }; return @sorted; }
And this is how you can use it:
my @unsorted = (9, 4, 2, 6, 1); my @sorted = sortArray(\@unsorted);
You can also use it's validate method for named parameter if your subroutine is likely to get bigger
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HOW Can I pass the array into my subroutine?
by snowsky (Initiate) on Apr 13, 2007 at 14:20 UTC | |
by GrandFather (Saint) on Apr 13, 2007 at 22:34 UTC |