I guess you would reply that you ARE using prototypes, but I doubt you are using strict and warnings. If you were then you would get "Request::aaa() called too early to check prototype".
The @ prototype is pretty useless. It accepts a list (not just an array), a single scalar (since that is a single entry list), and even nothing, since an empty list is still a valid list.
Yes you need to use references for this:
use warnings; use strict; sub Request::aaa(\@\@); #main.pl my @a1 = qw (the quick brown fox); my @a2 = qw (theres more than one way); Request::aaa(@a1, @a2); package Request; sub aaa(\@\@) { my @array1 = @{shift()}; my @array2 = @{shift()}; } 1;
Notice how the prototype has to be pre-defined, like with C/C++. Very few people like or understand prototypes, so it might be better to use:
use warnings; use strict; #main.pl my @a1 = qw (the quick brown fox); my @a2 = qw (theres more than one way); Request::aaa(\@a1, \@a2); package Request; sub aaa { my @array1 = @{shift()}; my @array2 = @{shift()}; } 1;

Here the caller has to know that a reference is being passed - that's the \ in front of the array (\@a1, \@a2)

In reply to Re: How to pass two arrays to a sub? by cdarke
in thread How to pass two arrays to a sub? by sanjay nayak

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.