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

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
June 10, 2021 08:28
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
20210610102748.66e0697c@pc09
On Thu, 10 Jun 2021 10:20:09 +0200, 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];
>         # ...

This is already supported by `each`:

$ perl -wE'my@x="a".."f";while(my($idx,$v)=each@x){say"$idx:$v"}'
0:a
1:b
2:c
3:d
4:e
5:f

> ... 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.

-- 
H.Merijn Brand  https://tux.nl   Perl Monger   http://amsterdam.pm.org/
using perl5.00307 .. 5.33        porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.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