Mike Blezien wrote:
> Hello,
>
> what is the best way to pass an array to a sub routine, IE.
You can't pass an array to a sub. You can only pass a list of scalars.
>
> my @fields = qw(one two three);
>
> send_array(@fields);
>
>
> sub send_array {
> my @ary = @_;
Whatever you passed ends up in @_. There's no way for the sub to know how
this data was passed, if it matters.
> # do stuff here....
> }
>
> is this the most effective way to pass an array to sub
> routine or is there a better way to do this.
If your sub just needs a list of values, what you've done is fine. If your
sub somehow needs to know about the @fields array, perhaps to modify it or
add or remove elements, you have to pass an array reference. Then you
manipulate the array via the reference inside the sub.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>