You are aware thatwill evaluate to the number of elements returned by foo rather than return the last one of them, right? :)scalar (@x = foo(1,2,3,5));
Yes, of course. I wrote that in reference to my $x = foo(1); setting $x to 1 :oP
I agree that it would be a rare case when the flattened array would be an acceptable return value, but I still don't like the idea of throwing away data. Oh, well. The only alternative I can think of is the hideous
return wantarray ? @arr : $#arr ? \@arr : $arr[0];
which borders on the obfuscated. I wouldn't use something like that if I were you. Of course I'm me, and love using lines like that, but I digress...
Zaxo's suggestion of using $arr[-1] makes sense too, especially if the sub is doing something cumulative with its args. Imagine a sum() function that keeps track of all the intermediate sums, or whatever.
In reply to Re^3: Context aware functions - best practices?
by LAI
in thread Context aware functions - best practices?
by Aristotle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |