in reply to foreach and arrays
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:
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.print 'I like'; foreach ('spam', 'spam', 'spam', 'eggs', 'and', 'spam') { print " $_"; } print ".\n";
The result is, of course:
$ spam.pl I like spam spam spam eggs and spam. $
|
|---|