Re: RFC 120 (v2) Implicit counter in for statements, possibly $#.
[email protected] (Mike Pastore) Fri, 18 Aug 2000 15:35:49 -0500 (CDT)
| Newsgroups | perl.perl6.language.flow |
|---|---|
| Message-ID | <[email protected]> |
On 18 Aug 2000, Ariel Scolnicov wrote:
> Actually, this suggests that C<values @array> should return
> C<(@array)> (a copy of the values), and C<keys @array> the list
> C<(0..$#array)>. But those aren't very useful.
I like the proposed syntax! I also think that C<keys @array> would be
useful, I often use arrays as integer-based lookups (like for database
results, primary keys and field names). To loop through a list like that,
where the array doesn't start at 0, nor has a consistent increment, I
practically have to kloodge the darn thing, doing:
$i = 0;
foreach(@array) {
$i++;
...
}
or:
for($i = 0; $i <= $#array; $i++) {
next unless $array[$i];
...
}
this:
while(($index, $value) = each(@array)) {
...
}
Seems much more elegant, although maybe we should stick to for* commands
for arrays.
--
Mike Pastore
[email protected]