When you need to pass arrays or hashes to a subroutine, learn to pass them as references - it will save you a lot of headaches. As others have already said, the parameter list gets flattened out into a list of scalars, but if all you pass to the subroutine is scalars (references are scalars), then you are all right.
#!/usr/local/bin/perl use strict; my @ar; sub test_args{ my ($ar_arrayref, $t) = @_; print "t = $t\n"; print "ar = @$ar_arrayref\n"; print "element 0 of array \@ar = $ar_arrayref->[0]\n"; ### ### or create a new array from the reference ### my @test_ar = @$ar_arrayref; print "element 0 of array \@test_ar = $test_ar[0]\n"; } push (@ar,"one"); push (@ar,"two"); test_args(\@ar,"three"); ----------------------------- output: t = three ar = one two element 0 of array @ar = one element 0 of array @test_ar = one
HTH.

In reply to Re: passing array as an argument by hmerrill
in thread passing array as an argument by podian

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.