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

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

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

8条回答
  •  野性不改
    2021-02-13 16:12

    See Schedule::ByClock:

    #!/usr/bin/perl
    
    use strict; use warnings;
    use Schedule::ByClock;
    
    my $scheduler = Schedule::ByClock->new(0, 20, 40);
    
    while ( defined( my $r = $scheduler->get_control_on_second ) ) {
        printf "%02d\n", $r;
    }
    

    All the caveats others pointed out still apply, but I think the module is neat.

提交回复
热议问题