in reply to Re: Re: array or scalar, that's the question
in thread array or scalar, that's the question
$foo = 3; @bar = (1, 2, 3); return $foo; # (3) return @bar; # (1, 2, 3)
In a scalar context, both of these versions will return 3 (the last element in the list returned). In a list context, you get 3 or 1, 2, 3. Just returning @bar, though, is sufficient for both cases, because it's your calling code that would want to act on the results. Make sense?
If you're wanting to return a real solid array (so that you can return @foo, @bar without flattening it into one big list), you need to return references to each array.
return (\@foo, \@bar); ... my ($fooref, $barref) = your_function();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: array or scalar, that's the question
by Juerd (Abbot) on Jan 02, 2002 at 00:21 UTC | |
by Fastolfe (Vicar) on Jan 03, 2002 at 00:01 UTC |