How can I tell Perl to run some code every 20 seconds?

后端 未结 8 805
余生分开走
余生分开走 2021-02-13 15:45

How can I tell Perl to run some code every 20 seconds?

8条回答
  •  灰色年华
    2021-02-13 16:28

    for (;;) {
        my $start = time;
        # your code;
        if ((my $remaining = 20 - (time - $start)) > 0) {
            sleep $remaining;
        }
    }
    

提交回复
热议问题