Salamihawk has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks,
I wish to write a small script for work, and I want to try to do it as correctly as possible the first time around. One of the things I'm trying to do is define a range of numbers 1..X with a variable that will cycle through that list in a for loop. For example, it will count from 1 to 4, but then once it gets incremented again ($i++ in a loop for example), it goes straight back to 1 and not 5.
I thought about doing something like:
if ( $i > 4 ) { $i = 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "Round Robin" variable range?
by hdb (Monsignor) on Jan 31, 2014 at 11:26 UTC | |
by Salamihawk (Initiate) on Feb 01, 2014 at 15:19 UTC | |
|
Re: "Round Robin" variable range?
by johngg (Canon) on Jan 31, 2014 at 11:50 UTC | |
|
Re: "Round Robin" variable range? (range operator / modulus )
by Anonymous Monk on Jan 31, 2014 at 11:17 UTC | |
|
Re: "Round Robin" variable range?
by kcott (Archbishop) on Feb 01, 2014 at 03:26 UTC | |
|
Re: "Round Robin" variable range?
by Laurent_R (Canon) on Jan 31, 2014 at 16:40 UTC |