Forum Moderators: coopster & phranque

Message Too Old, No Replies

Loop is not working

         

DrDoc

3:49 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a script that is supposed to run, then sleep for X minutes, then keep running, sleep, run, etc. But for some reason it seems to exit instead of sleep. Any idea why?

#!/usr/bin/perl 

use Digest::MD5 qw(md5_hex);
use DBI;

&dostuff;
exit;

sub dostuff {
if(-e "myfile.ini") {
open(INIREAD, "myfile.ini");
@file = <INIREAD>;
close INIREAD;
$sleepingtime = int(substr($file[0], 0, -1)) * 60;
}
else {
$sleepingtime = 60*60;
}

#
# do a bunch of stuff
#

sleep($sleepingtime);
&dostuff;
}

DrDoc

3:51 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since this script is supposed to run forever, would it be better to replace the lines:

&dostuff;
exit;

...with:

while(1) {
&dostuff;
}

...and remove the call to

dostuff
after the
sleep()
?

tombola

10:04 pm on Mar 18, 2004 (gmt 0)

10+ Year Member



Yep, that should work.

while(1) {
&dostuff;
}

exit;

sub dostuff {
$sleepingtime = 5;
$count++;
sleep($sleepingtime);
print "$count\n";
}

DrDoc

10:48 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just found the problem... An obscure error in one of the modules generated a die(). :(