develooper Front page | perl.perl5.porters | Postings from June 2021

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
Dan Book
Date:
June 10, 2021 08:27
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
CABMkAVVs+-zS08XnL3Kud5OSgtDi1e9Rq+Sghq_mpn5GzmHciQ@mail.gmail.com
On Thu, Jun 10, 2021 at 4:20 AM Marco Fontani <fontani@gmail.com> wrote:

> >     for my ($key, $value) (%hash) { ... }
>
> Could:
>
>     for my ($index, $value) (@array) { ... }
>
> ... be in the cards?
>
> I always find it tiring to have to iterate by index using a weird:
>
>     for my $i (0..$#array) {
>         my $value = $array[$i];
>         # ...
>
> ... and I'd rather the golang way (unsure if other languages have it)
> of being able to iterate either by value, or key/value for
> maps/hashes, or index/value for arrays, specifically.
>

Not likely, because this would already have the meaning of iterating over
the array 2 elements at a time. You could do something like:

foreach my ($i, $elem) (%array[0..$#array]) {

Up to you whether you think that's more understandable...

-Dan

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