How can I tell Perl to run some code every 20 seconds?
It is better to use some event library. There are a couple of choices:
IO::Async::Timer::Periodic
use IO::Async::Timer::Periodic;
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
my $timer = IO::Async::Timer::Periodic->new(
interval => 60,
on_tick => sub {
print "You've had a minute\n";
},
);
$timer->start;
$loop->add( $timer );
$loop->run;
AnyEvent::DateTime::Cron
AnyEvent::DateTime::Cron->new()
->add(
'* * * * *' => sub { warn "Every minute"},
'*/2 * * * *' => sub { warn "Every second minute"},
)
->start
->recv
EV::timer
etc.