in reply to Re: Re: Returning two arrays..
in thread Returning two arrays..

I believe that
@all = (\@foo, \@bar); return @all;
and
return \@foo, \@bar;
are identical so far as perl is concerned. Kind of like
print (1, 2, 3, 4); # and print 1, 2, 3, 4;

Anyway my suggestion is that if you're expecting a set number of elements from a subroutine then you can do something like this:

my ($aryref1, $aryref2) = subroutine(); # or if you want the longer way. my $aryref1; my $aryref2; ($aryref1, $aryref2) = subroutine();
Note that if a subroutine returns a list and you do something like:
my $ret = subroutine();
Then $ret will be the number of elements in the list that subroutine returned, not the first.

Jacinta

Replies are listed 'Best First'.
Re: Re: Re: Re: Returning two arrays..
by mr_mischief (Monsignor) on Jan 04, 2002 at 21:26 UTC
    The difference is you can't push onto a returned list. If you've many references to return or don't know how many you need to return at compile time, then an array will be much more handy. I just pointed out that for something this simple it does the same from outside the sub. That doesn't mean they'll each scale as well as the other.