paragkalra has asked for the wisdom of the Perl Monks concerning the following question:

I am sure there should exist some default variable which holds the current index of the array when we loop through it. Does it?

  • Comment on Variable that holds current index of the Array

Replies are listed 'Best First'.
Re: Variable that holds current index of the Array
by LanX (Saint) on May 12, 2010 at 09:13 UTC
    In almost all cases you don't need the index in a simple foreach loop, because the loop-variable is an alias, i.e. you can change the actual array element directly.

    If you really wanna know the index you have to use a c-stile for-loop.

    Cheers Rolf

Re: Variable that holds current index of the Array
by Corion (Patriarch) on May 12, 2010 at 07:41 UTC

    No. You will have to implement your own counter.

Re: Variable that holds current index of the Array
by toolic (Bishop) on May 12, 2010 at 15:06 UTC
Re: Variable that holds current index of the Array
by JavaFan (Canon) on May 12, 2010 at 09:52 UTC
    I am sure there should exist some default variable which holds the current index of the array when we loop through it. Does it?
    No need to ask others to donate their time to answer such trivial questions. All special variables are listed in the perlvar manual page. You could have answered this question yourself - only reading skill required!