![]() |
|
good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Can I check if a loop's scope is entered for the first time?by LanX (Saint) |
on May 05, 2018 at 13:52 UTC ( #1214094=perlquestion: print w/replies, xml ) | Need Help?? |
LanX has asked for the wisdom of the Perl Monks concerning the following question:
For an iterator to work in Perl one needs to initialize it properly
(I used c-style for here for clarity*)
But I'd rather like to stay DRY and to write something like
Where countdown can elaborate if the loop is (re)entered and does the init step automatically. NB: Other languages have this feature for so called iterator objects. I'm wondering if this could be tricked into Perl without XS wizardy °...
Approaches ...
Cheers Rolf
*) please note that while(CODE){} and for(;CODE;){} have the same effect. °) many issues could be solved like this...
updateThe countdown iterator was used for demonstration only, I now plenty of ways to countdown. Iterators are a general issue.
Back to
Seekers of Perl Wisdom
|
|