One way is to use a closure to create a subroutine reference, this is a simpler version of anonymonk's &make_rollover.
$ perl -Mstrict -Mwarnings -E ' > my $cycle = do { > my $val = 0; > sub { return ( ( $val ++ ) % 4 ) + 1; }; > }; > > say $cycle->() for 1 .. 10;' 1 2 3 4 1 2 3 4 1 2 $
I hope this is useful.
Update: Corrected typo, s/ue/use/
Cheers,
JohnGG
In reply to Re: "Round Robin" variable range?
by johngg
in thread "Round Robin" variable range?
by Salamihawk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |