in reply to passing arrays to asubroutine

You can pass references to the arrays to your subroutine. Try something like this:
#!/usr/bin/perl -w use strict; # define some arrays my @array1 = qw/apple orange/; my @array2 = qw/pear strawberry/; # call the subroutine passing references to arrays &showFruits(\@array1, \@array2); sub showFruits { # get the array references my ($array1_ref, $array2_ref) = @_; # use the array references to get to arrays foreach my $f1 (@$array1_ref) { print "$f1\n"; } foreach my $f2 (@$array2_ref) { print "$f2\n"; } }
Hope this helps,
Eric

Replies are listed 'Best First'.
Re: Re: passing arrays to asubroutine
by Ananda (Pilgrim) on Oct 28, 2002 at 05:25 UTC
    nice, simple and neat !! Anandatirtha