http://qs321.pair.com?node_id=1214099


in reply to Re: Can I check if a loop's scope is entered for the first time?
in thread Can I check if a loop's scope is entered for the first time?

Thanks, but remember I warned you in the CB! :)

> It would be nice if Perl's loop-keywords would also recognise an Iterator::* object and would treat it as expected... (internally rewriting it C-style, whatever).

I doubt this can be retro fitted without bracking backwards comaptibility.

You'd need a new keyword, like iter for my goal, this could actually be implemented with pluggable keywords.

Please note that you can already overload the diamond operator of a class to make the object an iterator (like a filehandle does)

This should work:

while ( my $next = <$obj> ) { ... }

but letting a generator init an iterator once wouldn't

while ( my $next = <generator($limit)> ) { ... }

because the diamond operator magically decides to become a file-glob here.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery