in reply to passing multiple items to a subroutine

If you have to give more then one array to a subroutine, you have to use references.
my @array1 = (0..9); my @array2 = ('a'..'l'); f(\@array1, \@array2);


Update: In your function you can access the arrays via the references (and change the original Arrays, or you copy them to local arrays, if you dislike the references...

sub f { my $aref1 = shift; my $aref2 = shift; print "$_\n" for @$aref1; ... }


or

sub f { my @a1 = @{shift}; my @a2 = @{shift}; print "$_\n" for @a1; ... }

Replies are listed 'Best First'.
Re: Re: passing multiple items to a subroutine
by Anonymous Monk on Mar 08, 2004 at 13:48 UTC
    you have to use references

    That's what the OP is doing.

    The error is that (s)he is mixing shift and @_ inside the sub.

    A reply falls below the community's threshold of quality. You may see it by logging in.