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

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

Thread Previous | Thread Next
Ed Avis via RT
November 28, 2016 08:46
[perl #130038] Builtin variable for loop index in foreach
Message ID:
Translating the loop at compile time into a new builtin foreach_idx sounds sensible, and it effectively automates what the programmer currently has do to in the code.  But if $# is a lexical scoped at compile time to the for loop, it won't be available in subroutines called from the loop.  This makes it inconsistent with next/last/redo, which do work from subroutines (matching the enclosing loop at run time).  Personally speaking I'd be fine with that (I consider always allowing 'next' from a subroutine something of a wart on the language) but I just mention the asymmetry.

One advantage of a new builtin loopidx rather than $# would be that you could specify loopidx(LABEL).  This might be another point in favour of a compile-time translation approach, that it could allow loopidx(LABEL) to be implemented more easily.

via perlbug:  queue: perl5 status: open

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