It's funny how as soon as you learn/meet/hear/read 
something/someone/something you see/hear it/him/her everywhere.

I saw this last night in an article by R. Schwartz and then this morning 
again somewhere else. Problem being - how to count to N and then start over 
(counting on your fingers, for example). Randall Schwartz's article was 
about producing a string of days, i.e. "Mon, Tue, Wed", that would also 
wrap around: "Sat, Sun, Mon".

My solution was to use:
@days = qw/Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun/  #  ;-)

It worked, but modulus (which I only knew as the "remainder tool") does this 
very nicely:

#!/usr/bin/perl
use warnings;
use strict;

# using modulus for a counter that "wraps around"
# $x counts from 1 to 20
# $i counts from 1 to 10 and then starts again with 1...

my ($i, $x);

for ($x = 1; $x <=20; $x++) {
   print "Original value: $x\t";
   $i = $x % 10;
   print "Modulus value: $i\n";
}

Maybe this is interesting to others as well who slept through too many high 
school math classes. (If someone thinks this is too basic or out of place 
here, please let me know privately.)

-- 
Kevin Pfeiffer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to