The best way to do this all depends on what you're looking to do with the data.

The easiest way is to just pass the array -

mysub(@myarray);
Now you're not going to be able to modify the array, just use the data that's passed. You're also not going to be able to tell which things were actually part of that array. Meaning if you do..
somesub(@somearray, $somescalar);
They are all passed to the sub as one big list. This also means that if you pass two arrays, they are passed as one big list.. without a good way to tell them apart.

Now.. you can explore the wonderful world of refrences if you want to modify the actual arrays and/or be able to differentiate between the two arrays. To pass a refrence, you do the following..

somesub(\@somearray, \$somescalar);
Now what's passed is actually two scalars that happen to be refrences to your data (not just some copy of the contents of those variables).

Now to access them, you need to derefrence them. There are various methods to do this. Instead of me trying to reinvent the wheel (and doing it much poorer), I'll defer to some articles that do a much better job of this than I can. For starters, read one of merlyn's articles. There's also perlref and perldsc.

Hope this helps..
Rich


In reply to Re: Passing arrays by rchiav
in thread Passing arrays by Ras

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.