Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: passing multiple items to a subroutine

by Crian (Curate)
on Mar 08, 2004 at 13:44 UTC ( [id://334802]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://334802]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-19 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found