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

skippable arguments in for loops

Thread Next
Carl Mäsak
September 21, 2005 23:44
skippable arguments in for loops
Message ID:
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] <,Thu&sel=182#l318>

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About