in reply to for, foreach and $_...
This style is definitely the common way of iteratively accessing the elements of an array, but the more idiomatic approach of iterating over an array, when the index isn't needed, is simplyfor(0 .. $#array) { ... }
That works because an array in a list context flattens to a list (as opposed to in scalar context, where it yields the number of elements it contains, which is almost always $#array + 1) providing for with a list to iterate over.for(@array) { ... }
See. perlsyn for more info.
HTH
_________
broquaint
1 internally, I believe this is implemented as a while(COND) { ... } continue { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: for, foreach and $_...
by larsen (Parson) on Aug 18, 2003 at 14:21 UTC |