You have several ways to go for this. Pick one that fits what you want.
Inside the sub, you can say
The second two are equivalent.sub CallSub { my ($IGot, $TheBlues, @Array) = @_; # or #(my $IGot, my $TheBlues, @_) = @_; # or else shift the first two in # my ($IGot, $TheBlues) = (shift, shift); # ... }
Another way is to pass in an array reference, either explicitly, or by defining CallSub with a prototype of ($$\@). In either case you would do that like this,
All these reflect a slight weakness in the design your question implies. There is a very tight binding between the definition of sub CallSub and the arguments given its use. That may be unavoidable, but the most natural subs seem to take an open list of like things. You may find that your design is better than the alternatives, but you can only benefit from examining what else you might do.sub CallSub # ($$\@) # if you choose { my ($IGot, $TheBlues, $Arrayref) = @_; # or some variation # ... }
After Compline,
Zaxo
In reply to Re: Passing multiple data types to a subroutine
by Zaxo
in thread Passing multiple data types to a subroutine
by Hagbone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |