Thanks James,

passing as a reference was basically what I was trying to recall,.... your example made that clear :)



--
Mike<mickalo>Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

James Edward Gray II wrote:
On Dec 9, 2003, at 8:49 PM, Mike Blezien wrote:

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>




Reply via email to