amadain has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks
I want to pass 2 arrays into a subroutine but when I try I do not succeed. I use the following code to pass the arrays and check whether they are passed properly
sub team_update { my (@Values, @teams) = @_; print "Values are\n@Values and teams are\n@teams\n"; exit 1; }
but the check shows that the @Values array is the only one thats populated. Is there another way of doing this
Bewildered

Replies are listed 'Best First'.
Re: arrays passed into subroutines
by wfsp (Abbot) on Nov 10, 2004 at 09:04 UTC
    The arrays get flattened into one long list. @_ pours it into the first place looking for a list i.e. @Values.

    You can pass the arrays as array references e.g. \@array.

    In the subroutine you then need to dereference them, say,

    my $array_ref = shift; my @array = @{$array_ref};
    The perlreftut is a good place to delve deeper into refs.
      Thanks. The array references worked fine
Re: arrays passed into subroutines
by neilh (Pilgrim) on Nov 10, 2004 at 08:56 UTC
    When passing arrays you need to use references, otherwise the first is greedy...

    For more info see perldoc perlref

    Neil

Re: arrays passed into subroutines
by Hena (Friar) on Nov 10, 2004 at 09:16 UTC
    Also if you use prototypes, you can make your sub to be like
    sub team_update (\@\@) { my ($values_ref,$teams_ref)=@_; }
    This would allow chaging the values within subroutine and also check that you call the subroutine properly (with strict).