![]() |
|
more useful options | |
PerlMonks |
Re: Returning first element of an array from a functionby davido (Cardinal) |
on Mar 17, 2004 at 07:47 UTC ( #337246=note: print w/replies, xml ) | Need Help?? |
In the case you provided, you would do something like this:
By wrapping the left hand side in parens, you put the assignment into list context, and the first element of that list is stored in $foo. For more complex cases, sometimes its helpful to wrap the right-hand-side in parens, and then index into the element that you want returned:
The latter method would allow you to return several elements at once. You could even do this:
...which would return the 2nd element to $foo, and the 1st element to $boo.
Dave
In Section
Seekers of Perl Wisdom
|
|