in reply to Optimizing with wantarray
If you call a subroutine in a scalar context, that context gets propogated to the expression that is calculating the return value automatically. Likewise, a list context. This is documented, and is not an "optimization", but a definition!
Remember, it's not just about list vs length of list... see my On Scalar Context for all the ways that this introduced context can affect the result.
Thus, a subroutine called in a scalar context could never have constructed any sort of list at any time during the return. It has to construct a scalar of the appropriate flavor. And for @foo, that's gonna be the length of the foo array, and none other.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Optimizing with wantarray
by dragonchild (Archbishop) on Aug 06, 2004 at 02:51 UTC | |
by merlyn (Sage) on Aug 06, 2004 at 07:34 UTC |