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:
Kent Fredric
Date:
November 28, 2016 09:40
Subject:
Re: [perl #130038] Builtin variable for loop index in foreach
Message ID:
CAATnKFCnvA=DkB1KAPOT776Uo7VnOvFE+CcdfXFmivhLFioDwQ@mail.gmail.com
On 28 November 2016 at 22:34, Dave Mitchell <davem@iabyn.com> wrote:
>
>     for       -> $i    (....) { say "$i: $_" }
>     for $x    -> my $i (....) { say "$i: $x" }
>     for my $x -> my $i (....) { say "$i: $x" }
>
> for a suitable bikeshedding of '->'.


Yeah. There's also the possibility of a future of list expanding +
iteration step.

for my $iter -> my $a, $b, $c ( @items ) {
   say "$iter: $a, $b, $c";
}

Where "$iter" would only increment once for every three @items pooled
in via $a,$b,$c

Though I would expect any implementation we choose to have the values
in the order "index/value" or "key/value",
as that's pretty much how every other language with similar features does it.


-- 
Kent

KENTNL - https://metacpan.org/author/KENTNL

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