note
LanX
FWIW I tried [DOC://feature|<tt>feature</tt>] state with no avail. (the idea was to return a tied iterator)<P>
But this only works for the first initialization, test() is never called again<P>
<c>
use strict;
use warnings;
use Data::Dump qw/pp dd/;
use feature 'state';
my $x = 0;
sub test { warn ++$x; return $x }
for my $a (1..3) {
print "\n---\n";
while (state $z = test() ) {
print "$a:$z\n";
last unless $a--;
}
}
</c><P>
<c>
1 at d:/Users/lanx/pm/state_loop.pl line 7.
---
1:1
0:1
---
2:1
1:1
0:1
---
3:1
2:1
1:1
0:1
</c>
<div class="pmsig"><div class="pmsig-708738">
<p>Cheers Rolf<br>
<sub>(addicted to the Perl Programming Language and [http://i.dailymail.co.uk/i/pix/2014/07/14/article-2690897-1F9F6C0E00000578-463_964x629.jpg|☆☆☆☆] :)
<br> <i> [id://1153804|Wikisyntax for the Monastery]</i>
</sub> <P>
</div></div><!-- Wiki2Monks {"version":1.1416} -->
1214094
1214094