in reply to Returning two lists from a sub

An alternative is to pass references to the arrays to the function:
getlists(\@a, \@b); print join(" ",@a),"\n",join(" ",@b); sub getlists { my @foo = (1,2,3); my @bar = (4,5,6); @{$_[0]} = @foo; @{$_[1]} = @bar; }

or

getlists(\@a, \@b); print join(" ",@a),"\n",join(" ",@b); sub getlists { my ($foo, $bar) = @_; @$foo = (1,2,3); @$bar = (4,5,6); }

Replies are listed 'Best First'.
Re^2: Returning two lists from a sub
by MaxKlokan (Monk) on Jun 09, 2007 at 17:39 UTC
    Didn't the OP say that he wants to avoid that?