I've done this plenty of times in the past using something like:
and one the receiving end, doing:CallSub($Igot,$TheBlues);
The new wrinkle for me in the current situation is that I'd like to send the subroutine two different data types ... and array and a couple of scalars:my ($Igot,$TheBlues) = @_;
And when received on the subroutine end, I'd like to be able to isolate the scalar values from the array value.@Array = qw(one two three four); $Igot = 'whatever'; $TheBlues = 'whateverelse';
It seems that I can't pass multiple data types to the subroutine. I could easily be wrong (due to ignorance of how it's done).
One solution that occurred to me would be to "shift" the scalars into the array, and then disassemble the business after it gets to the subroutine:
and at the subroutine:$Igot = shift(@Array); $TheBlues = shift(@Array); CallSub(@Array);
And the what's left is the array I passed to the subroutine, minus the two scalars I added.my (@PassedArray) = @_; my $TheBlues = $PassedArray[0]; my $IGot = $PassedArray[1];
But that sure seems like the long way around the block (and potentially easier to make mistakes when unraveling), so I'll ask what I'm hoping is a question with a how-to answer: Can multiple data types be passed to a subroutine?
In reply to Passing multiple data types to a subroutine by Hagbone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |