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:
Dave Mitchell
Date:
November 9, 2016 09:44
Subject:
Re: [perl #130038] Builtin variable for loop index in foreach
Message ID:
20161109094430.GE3081@iabyn.com
On Tue, Nov 08, 2016 at 10:35:07AM +0000, Ed Avis wrote:
> Dave Mitchell wrote:
> 
> >For ranges, e.g. (1..10) and ('a'..'z'), it only records the current value and the last value.
> 
> But for numeric ranges, if you know the current value it is just a subtraction to find its index.

No, at the point where you have iterated  'for (11..20) {}' say, 7 times,
exactly two values are currently stored: 17 and 20. There is no way (in
general) to deduce that value '7' from that. Extra bookkeeping of one form
or another would need to be added.

-- 
A walk of a thousand miles begins with a single step...
then continues for another 1,999,999 or so.

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