in reply to Re^2: Odd behaviour with $. and <DATA>
in thread Odd behaviour with $. and <DATA>

But (since I'm not allowed to use the phrase beg the question) I wonder why that is .. foreach suggests that, for each element in the list, it's going to do something. It doesn't suggest that it's going to slurp up the entire list at once.

Indeed: but before iterationg over the list, the latter has to be created, which should answer your question. Said, this, the list has to be created unless we have "lazy evaluation", which we curretly have not, with the exception of a pair of special cases, whereas Perl 6 will have it by default -and you'll generally need to explicitly tell it to do differently, if you want so!- in fact for will be the default for iterating over iterators, be them regular lists, filehandles or more exotic objects.