Bug#374008: foreach over n items at a time (where n != 1)
Dominic Hargreaves
dom at earth.li
Tue May 31 20:10:59 UTC 2011
On Fri, Jun 16, 2006 at 03:09:12PM -0400, Anthony DeRobertis wrote:
> Syntax like this would be nice:
>
> foreach ($i, $j, $k) (@arr) {
> ...
> }
>
> The effect would be something like this:
>
> for ($_tmp = 0; $_tmp < @arr; $_tmp += 3) {
> $i = $arr[$_tmp];
> $j = $arr[$_tmp+1];
> $k = $arr[$_tmp+2];
> warn "non-congruant number of items in foreach" if $_tmp+2 >= @arr;
> {
> ...
> }
> }
>
> That warning message is horrible, but... I hope that illustrates the
> idea.
>
> Naturally, you could also use my:
>
> foreach (my ($i, $j, $k)) (@arr) {
> ...
> }
>
> [I'm guessing the parentheses around the list of variables would make
> parsing easier. That's the only reason I've placed them there.]
Hi Anthony,
I think the best place to discuss such improvements to the language
is probably on p5p[0]. We could forward this upstream, but we'd then
just become a go-between in any ensuing discussions.
Do feel free to CC this bug in though.
Cheers,
Dominic.
[0] <http://lists.perl.org/list/perl5-porters.html>
--
Dominic Hargreaves | http://www.larted.org.uk/~dom/
PGP key 5178E2A5 from the.earth.li (keyserver,web,email)
More information about the Perl-maintainers
mailing list