in reply to foreach and arrays

My understanding is that a foreach loop processes the array sequentially, just as a "standard" for loop would do.

I think where the statement <quote>there is no way of knowing where in a list one is</quote> comes from is that there is no explicit loop variable - if you want to know where you are up to in the array, you have to keep track of that yourself. However, the foreach is generally processing a list, no necessarily an array. I could define the contents of the list explicitly, such as:

print 'I like'; foreach ('spam', 'spam', 'spam', 'eggs', 'and', 'spam') { print " $_"; } print ".\n";
and there is no way of knowing that, for example, when I am printing the work "eggs" that this is the fourth time through the loop.

The result is, of course:

$ spam.pl I like spam spam spam eggs and spam. $