Re: RFC 120 (v2) Implicit counter in for statements, possibly $#.
[email protected] (Jonathan Scott Duff) Fri, 18 Aug 2000 10:42:11 -0500
| Newsgroups | perl.perl6.language.flow |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Aug 18, 2000 at 10:12:02AM -0500, Christopher J. Madsen wrote:
> I would say you can't use implicit $_ with an index; you use explicit
> $_ instead.
Sounds like "Don't Do That" to me :-)
>
> foreach $_ $index (@array) { ... }
>
> It's only 3 characters, and it makes for a nice consistant syntax.
Yep, but it might also be a source of confusion too. There's no way
to help the programmer realize that they've screwed up when they do.
for $index (@array) {
print "$_ is at position $index\n"; # Oops!
}
In this example, the programmer may realize his mistake when he sees
" is at position 0", but in the real world, the body of the loop may
be *much* more complicated. How do we help the programmer when he
screws up?
-Scott
--
Jonathan Scott Duff
[email protected]