array parameters

  • Thread starter Daniel Molina Wegener
  • Start date
D

Daniel Molina Wegener

Hello,

I have a trouble passing multiple array parameters in
Perl 5. I handle parameters using @_, but I can't handle
multiple array parameters using @_.

sub mysub {
my ($arg1, @arg2, @arg3) = @_;
# do something with args...
}

Then I can't handle @arg2 and @arg3, because Perl 5
does not takes @arg2 and @arg3 as one array. Any other way
to handle array parameters?. Any way to pass by reference
any parameter in subs?.

Regards...
 
A

A. Sinan Unur

Hello,

I have a trouble passing multiple array parameters in
Perl 5. I handle parameters using @_, but I can't handle
multiple array parameters using @_.

sub mysub {
my ($arg1, @arg2, @arg3) = @_;
# do something with args...
}

Then I can't handle @arg2 and @arg3,
....

Any way to pass by reference any parameter in subs?.

Interestingly enough, perldoc perlsub has a section titled "Pass by
Reference".

Sinan.
 
J

Jürgen Exner

Daniel said:
I have a trouble passing multiple array parameters in
Perl 5. I handle parameters using @_, but I can't handle
multiple array parameters using @_.

sub mysub {
my ($arg1, @arg2, @arg3) = @_;
# do something with args...
}

Then I can't handle @arg2 and @arg3, because Perl 5
does not takes @arg2 and @arg3 as one array.


Actually it does. The argument list is flattened into one single list. And
that is exactly your problem.
Any other way
to handle array parameters?

As described in 'perldoc perlsub' you should use references.
Any way to pass by reference

Sure. The method described in 'perldoc perlsub' normally works great.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top