Perl alternate execution

Question:

There is a cron script that executes the function

Generate(17, "test",3,1 , int(rand(3)+1));

The last argument is a random number, which is already passed to the function itself. How to write the argument so that a number from one to three is passed in turn, each time this script is executed on the crown?

Answer:

You must store the counter somewhere, and pass the remainder of division by 3 to the function:

my $counter =  read_from_config()
Generate(17, "test",3,1 , $counter%3 +1);
save_to_config( ++$counter );

because the remainders of division by 3 can be: 0, 1, 2, then we must add 1 here to get your required: 1, 2, 3

Scroll to Top