Hello,
what is the best way to pass an array to a sub routine, IE.
my @fields = qw(one two three);
send_array(@fields);
sub send_array { my @ary = @_; # 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.
That depends on how you define "effective". The way you showed is the easiest. References are probably better in some respects though, if you don't mind the complications:
my @array = qw(1 2 3); my @other_array = qw(dog cat pig);
send_array([EMAIL PROTECTED], [EMAIL PROTECTED]);
sub send_array { my($nums, $anims) = @_; # do stuff with references here, for example
print $nums->[1], ' ', $anims->[2], "\n"; # prints "2 pig" }
Hope that helps.
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>