[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Finding array index



You pretty much answered your own question. If you want an index, you use
the 'for' loop (or use 'foreach' and have another variable that gets
incremented on each iteration).

Incidentally, I don't think you want to write a 'for' loop using commas,
as you've shown below. It's worth pointing out, because it's syntactically
OK - it just won't do what you want. What you have is equivalent to

@alist = ($i = 0, $i <= $#array, $i++);
for (@alist) { do stuff }

where the elements of @alist are just 1, 1 and 0. Use semicolons.

On Thu, 5 Nov 1998, Mark Yannuzzi wrote:

> Is there a shortcut for finding the current array index when using the
> "foreach" loop?  Or, must you use "for ($i = 0, $i <= $#array, i++)"?  I
> know $#array stores the last index.
> 


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch