Dear monks,

I want to pass a few scalars and *two* lists two a sub. As far as I can see my initial attempts at using @_ in a simple sense didn't work. Here is my code snippet:
sub process_something { my $s1; my $s2; my $l1; my $l2; ($s1, $s2, @l1, @l2) = @_; . . . } process_something($scalar1, $scalar2, @list1, @list2);
The problem is that when the sub is called and the first assignment is made, @l1 grabs all the elements of both @list1 and @list2.

How can I pass two consecutive lists to my sub and have them assigned to two different list variables in a correct manner? I've searched the PerlMonks site but just found an example with hashes which confused me a lot. All I need is a simple construct in which I'll have two correct @l1 and @l2 at the end.

Thanks in advance.

In reply to How to pass two lists to a sub? by YAFZ

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.