in reply to How to pass two lists to a sub?

You can pass two arrays without flattening them or references if you use function prototypes:
sub foo(@@){ }
Many build-in functions (e.g., push) has two list parameters. Read about it in the docs: type "perldoc perlsub"

Replies are listed 'Best First'.
Re^2: How to pass two lists to a sub?
by Joost (Canon) on Nov 05, 2004 at 19:46 UTC
    Almost, but not quite.
    sub foo(\@@) { my ($aref,@rest) = @_; }
    is the prototype for push: push does not have two list parameters, because you cannot have more than one list parameter; it has an array parameter, which automatically gets passed as an array reference, followed by a list (the rest of the arguments).

    If you really want to use prototypes for two arrays you should use \@\@, optionally followed by more arguments:

    #!/usr/local/bin/perl -w use strict; my @a = qw(a b c d); my @b = qw(e f g h); my @c = qw(i j k l); sub test(\@\@@) { my ($a,$b,@rest) = @_; print "@$a\n@$b\nrest is @rest\n"; } test(@a,@b,@c); __END__ a b c d e f g h rest is i j k l

    update: I should probably make clear that using prototypes in Perl is generally frowned upon except in exceptional circumstances. There are good reasons for this attitude, but let me just point out that in the above example you can accomplish the same result if you pass the arrays by reference explicitly, and it's shorter to create anonymous arrayrefs than to pass two arrays if you don't intend to use the arrays any other way:

    test( [qw(a b c d)], [qw(e f g h)], qw(i j k l)); sub test { my ($a,$b,@rest) = @_; print "@$a\n@$b\nrest is @rest\n"; }
    update2: fixed typo