OK, I understand how to pass a single value into a subroutine - I even understand how to pass two strings into a subroutine.
So how do I pass an array and a string? Or even a hash and an array into subroutines?
For instance, I have the following code:
sub printEachExpt { my @expNames= @_; my ($total, $n, $outputPath); $total = @expNames; $outputPath = $expNames[$total - 1]; print "The output path is $outputPath.\n"; print "The experiment files are:\n"; for ($n = 0; $n <= $total - 2; $n++) { print "$outputPath/$expNames[$n]\n"; } return(@expNames, $outputPath); } printEachExpt(@expNames, $outputPath);
What I'm putting in with the array are a number of names,
Con5.5A, Con6.5B, Con6.5C, Con6.5D.
What I'm submitting with the $outputPath string is /export/home/madraghrua/argentina .
What I get is the following:
The output path is /export/home/madraghrua/argentina. The experiment files are: /export/home/madraghrua/argentina/Con6.5A /export/home/madraghrua/argentina/Con6.5B /export/home/madraghrua/argentina/Con6.5C /export/home/madraghrua/argentina/Con6.5D
This is correct, but the input to the subroutine is concatenated together and I need to know which array element corresponds to what I need.
However, I would like to pass the array as an array and the string as a string. Or even two arrays. I pretty sure that I know I can do this in C - how do I do this in Perl? Is there a general way of passing variables for hashes as well?
Thank you in advance for your learned answers...
MadraghRua
yet another biologist hacking perl....
In reply to Passing different values into subroutines by MadraghRua
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |