Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Can I check if a loop's scope is entered for the first time?

by LanX (Sage)
on May 05, 2018 at 17:25 UTC ( #1214099=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1214099]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2022-08-09 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?