On Saturday 20 May 2006 23:13, SkyBlueshoes wrote: > I have a script that uses an infinite loop, I'm wanting to be able to > set a timer that when expired will run a subroutine, something sort of > like Poe's callback timer feature. How would I go about doing this? I > need to be able to set multiple timers on the fly within my script and > have them only run once. > > Sky Blueshoes
I'm sure there's a better way, but here's a simple scipt using threads and a simple timer subroutine: #!/usr/bin/perl -w use strict; use threads; my $timer1 = threads->create(\&timer, \&timer_test, 1, 0); $timer1->join(); sub timer { my($subroutine, $interval, $max_iteration) = @_; for (my $count = 1; $max_iteration == 0 || $count <= $max_iteration; $count++) { sleep $interval; &$subroutine; } } sub timer_test { print "Testing...\n" } You'd need to modify the timer subroutine in order to pass arguments to the routine executed by it. Stephen Kratzer CTI Networks, Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>