Daniel Carrera daniel.carrera-at-theingots.org |Perl 6| wrote:
Hello,
The following construction doesn't do what a user might expect:
for 0...@foo.elems -> $k { do_something($k,@foo[$k]) }
Obviously, the intention is to step through every key/value in @foo.
Buf @f...@foo.elems] does not exist. If @foo = (1,2,3); then
@foo.elems is 3, and @foo[3] is undefined.
Yes, I know that you could also have written:
for @foo.values -> $k { do_something($k,@foo[$k]) }
But I point out that the earlier code sample was given to me on IRC at
#perl6. If one of the current developers can make that mistake, other
users will too. I cannot say whether it makes sense to alter the
language because of this. You are the language experts. I just wanted
to raise a likely point of confusion among users.
Cheers,
Daniel.
Write ^...@foo.elems as a shortcut of 0...@foo.elems, which is the
variation to exclude that endpoint if you would rather not write
0...@foo.elems-1.
--John