Every - return true every N cycles or S seconds


Every documentation  | view source Contained in the Every distribution.

Index


NAME

Top

Every - return true every N cycles or S seconds

SYNOPSIS

Top

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

FUNCTION-ORIENTED INTERFACE

Top

every( $number [, @id] )

every( seconds => $number [, @id] )

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, even if you call it twice on the same line, e.g.

 print "hello" if every(5) or every(6);

The every() function will use the Devel::Callsite module to find the opcode and interpreter context (both unique numbers).

The optional @id is a list of arguments that compose a unique identifier. In other words, every(100, 'x') will run its 100 cycles independently of every(100, 'x', 'y').

DESCRIPTION

Top

Returns true when the conditions (cycles or seconds elapsed) are met. The first cycle doesn't count (so e.g. every(100) will be true at 100, 200, etc.)

Thanks to Dr.Ruud on comp.lang.perl.misc for helping with this idea, and to Jerry Hedden for cleaning it up. Thanks to Ben Morrow for getting Devel::Callsite started, which module is essential to Every.

Thanks to Jerrad Pierce and ikegami for the bug reports and help.

BUGS

Top

None known.

COPYRIGHT

Top

AUTHOR

Top

Ted Zlatanov <tzz@lifelogs.com>

SEE ALSO

Top


Every documentation  | view source Contained in the Every distribution.