vol*_*ron 11
如果您希望Perl程序在设定的时间或时间间隔执行,那么您可能需要考虑crontab或另一个调度程序.
如果要在Perl脚本中执行等待,则可以使用一些易于部署的选项.
sleep($n) 系统调用,其中$ n是秒的数值usleep($n) 系统调用,其中$ n是微秒的数值Time :: HiRes提供了许多功能,其中一些功能会覆盖系统调用.一些功能包括:sleep(),usleep(),nanosleep(),alarm(),ualarm()
与系统调用不同usleep(),使用Time :: HiRes打包的那个允许睡眠超过一秒.
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep
clock_gettime clock_getres clock_nanosleep clock
stat );
Run Code Online (Sandbox Code Playgroud)
您很可能希望分叉您的进程,以便您的主程序可以继续工作,同时一个进程在后台休眠.
用途sleep():
sleep(120); # sleep for 120 seconds
Run Code Online (Sandbox Code Playgroud)
对于比一秒更精细的延迟,您可以usleep从Time::HiRes模块中使用.您也可以使用Perl的四参数版本,select()保留前三个参数undefined:
select(undef, undef, undef, 0.25); # sleep for 250 milliseconds
Run Code Online (Sandbox Code Playgroud)