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

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

Thread Previous | Thread Next
From:
Hugo van der Sanden via RT
Date:
November 28, 2016 11:47
Subject:
[perl #130038] Builtin variable for loop index in foreach
Message ID:
rt-4.0.24-25944-1480333647-992.130038-15-0@perl.org
On Mon, 28 Nov 2016 01:21:43 -0800, kentfredric@gmail.com wrote:
> If we take a different tack and propose, instead of some arcane magic,
> that we define a new keyword,
> 
> > for_idx
> 
> That can take *two* variables:
> 
> for_idx my $key, $value ( @array ) {
>     ...
> }
> 
> Then we get the benefit of explicitness, the benefit of clarity, and
> the benefit of
> working even in evals.

You also get the benefit that *you already have this*:

  while (my($key, $value) = each @array) {
    ...
  }

I'm guessing (wildly) that when the "experimental each on scalar" deprecation advances to removal, we could consider extending each() to lists to support:

  while (my($key, $value) = each(1, 2, @many)) { ... }

Hugo

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=130038

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