Hello Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.