in reply to Of foreach loops and counting

The easiest way I know of is to do something like.
foreach (0..$#array){ # do stuff, $_ holds iteration num. }


--eric

Replies are listed 'Best First'.
RE: Re: Of for each loops and counting
by turnstep (Parson) on Aug 09, 2000 at 20:27 UTC

    Or if you really want to use one of Perl's special variables, try this:

    for ($[..$#array) { ## Foo }
    since "0" is not necessarily the first element of the array. Of course, nobody should ever, ever change the $[ variable except as part of an obfuscated perl program. :)

RE: Re: Of foreach loops and counting
by Cirollo (Friar) on Aug 09, 2000 at 19:44 UTC
    Ok, and then I would just get my array values with $array[$_] instead of having the value be in $_. Sounds good to me. Thanks.