develooper Front page | perl.perl5.porters | Postings from November 2016

Re: [perl #130038] Builtin variable for loop index in foreach

Thread Previous | Thread Next
Aristotle Pagaltzis
November 28, 2016 00:48
Re: [perl #130038] Builtin variable for loop index in foreach
Message ID:
* Dave Mitchell <> [2016-11-08 11:36]:
> If we did this this, we would have to either:
> * update $# on each loop iteration, which would slow down all loop
>   iterations, or
> * give $# get magic that searches the context stack for a loop context,
>   then retrieves the current loop index stored in there. That wouldn't
>   slow down normal loops, but accessing $# itself might be quite slow.

The latter would be fine, just as a new builtin `loopindex` instead of
get magic on yet another new superglobal.

How much overhead (size, speed) on scopes would we incur if each frame
had a pointer to the innermost containing loop context? (On each scope
check what type the immediate containing scope is, then either set the
new scope’s containing loop pointer to the containing scope or copy the
containing scope’s loop context pointer.) Could `next`/`last` benefit
from that too?

Aristotle Pagaltzis // <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About