MadraghRua has asked for the wisdom of the Perl Monks concerning the following question:
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....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Passing different values into subroutines
by Boogman (Scribe) on Aug 31, 2000 at 21:29 UTC | |
by Adam (Vicar) on Aug 31, 2000 at 21:48 UTC | |
|
(kudra) Re: Passing different values into subroutines
by kudra (Vicar) on Aug 31, 2000 at 21:33 UTC | |
|
Re: Passing different values into subroutines
by Maclir (Curate) on Sep 01, 2000 at 03:06 UTC | |
by chromatic (Archbishop) on Sep 01, 2000 at 08:37 UTC |