Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: "Round Robin" variable range?

by johngg (Canon)
on Jan 31, 2014 at 11:50 UTC ( [id://1072830]=note: print w/replies, xml ) Need Help??


in reply to "Round Robin" variable range?

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found