You went to the trouble of writing some nice test code, but did you run it? It might help answer some of your questions...

First, shift only takes one element off the parameter list, so your test sub will give you:

$number = 3; @array1 = ("mary"); @array2 = ("had");

As for how the arguments are passed to the function, perl flattens out the argument list, so it will arrive as one big list (@_ to be exact), and you won't be able to tell where one list end and another begins. If you need to do this, you'll have to pass references, like so:

sub test { my $number = shift; my $arrayref1 = shift; my $arrayref2 = shift; # remember to dereference: @$arrayref1 etc. } # ......... my @a = ("mary","had","a","little","lamb","!"); my @b = ("London","Bridge","is"); # call sub test(3,\@a,\@b);

HTH

--
3dan

In reply to Re: Parameters, subs and the shift function by edan
in thread Parameters, subs and the shift function by Foggy Bottoms

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.