
Every - return true every N cycles or S seconds

for (0..200)
{
print_stats() if every(20); # every 20 cycles
print_times() if every(seconds => 5); # every 5 or more seconds
sleep 3;
}

Returns true every $number times it's called, or every time $number seconds have elapsed since the last time it was called. The every() function keeps track of where it was called by line. If you need to call it twice on the same line, e.g. print "hello" if every(5) or every(6); That won't work. The right way is to use an identifier, e.g. print "hello" if every(5, "a") or every(6, "b"); The reason is that caller() doesn't return a position, only a line number.

Returns true when the conditions (cycles or seconds elapsed) are met. Thanks to Dr.Ruud on comp.lang.perl.misc for helping with this idea, and to Jerry Hedden for cleaning it up.

None known.

Copyright 2008, Ted Zlatanov (Ð¢ÐµÐ¾Ð´Ð¾Ñ ÐлаÑанов). All Rights Reserved. This module can be redistributed under the same terms as Perl itself.

Ted Zlatanov <tzz@lifelogs.com>
