develooper Front page | perl.perl6.language | Postings from September 2005

skippable arguments in for loops

Thread Next
From:
Carl Mäsak
Date:
September 21, 2005 23:44
Subject:
skippable arguments in for loops
Message ID:
16d769b705092123436dc01c99@mail.gmail.com
hcchien raised the following question on #perl6[1]:

If I want to loop through a nine-element array three elements at a time, I do

my @a = 1..9;
for @a -> $x, $y, $z { say $x }

But what if I don't care about the elements 1,4,7? Would the following
be a sane syntax?

my @a = 1..9;
for @a -> undef, $x, $y { say $x }

FWIW, to me it looks fairly intuitive. undef here means "don't alias
the element, just throw it away"... gaal joked about using _ instead
of undef. :)

If the appropriate authority (p6l or @larry) likes this idea, I can
add a few tests to that end in the pugs tree.

[1] <http://colabti.de/irclogger/irclogger_log/perl6?date=2005-09-22,Thu&sel=182#l318>

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