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

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

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
November 28, 2016 00:48
Subject:
Re: [perl #130038] Builtin variable for loop index in foreach
Message ID:
20161128004823.GB75788@plasmasturm.org
* Dave Mitchell <davem@iabyn.com> [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?

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About