In a message dated Fri, 9 Aug 2002, Adam Lopresto writes: > I was wondering whether the Perl 'while (<>){' idiom will continue to be > supported in Perl 6? I seem to recall people posting example code the list > using it (although I can't dig any up), but it seems to me that if Perl 6's > lazy list implementation is sufficiently smart, it could just be replaced with > 'for <> {'. The only issues I can see are people using <> inside the loop, and > maybe something about the scope of $_. (Does a topicalized $_ change the value > of $_ outside of the loop?) >
for <> { ... } will be the new idiom, and it will be completely regular: a lazy iteration of a list, with implicit topicalization to $_. while <> {...} Might be supported as a special case, I haven't heard either way. But by switching while to for, no special syntactic sugar is necessary, unlike in previous Perls. I don't see why one couldn't use <> inside the for look. Either it's the same iterator inside and out (iterators associated with filehandles), in which case it'll do the right thing, or it's a different iterator (iterators scoped by block), in which case the inside lazy iterator will be monkeying with stuff that the outside lazy iterator has never, and will never, see. I don't know which it is, but either way, it seems like it would work fine in the case of a filehandle read (provided that iterators can look ahead and put stuff back on the buffer, which I understand they will be able to). Trey