http://www.perlmonks.org?node_id=226923


in reply to Context aware functions - best practices?

I think the wantarray solution is fine, and not all that awkward. That's what wantarray is for.

I think I can make a case for scalar foo LIST to return the last element of the result return wantarray ? @arr : $arr[-1]; instead of the first. A comma sequence behaves that way in scalar context, so that is the ordinary precedent competing with array count for behavior in scalar context.

A third possibility is to return a reference to the generated array. Some modules do that, but it is clearly not desired here.

No, I don't think you missed anything.

After Compline,
Zaxo