use POSIX qw( strftime );
sub next_day {
my $start_d = (localtime)[3];
for (;;) {
sleep(30*60);
my $d = (localtime)[3];
return if $d != $start_d;
}
}
next_day() for 1..5;
print strftime("%Y-%m-%d\n", localtime());
next_day() for 1..4;
print strftime("%Y-%m-%d\n", localtime());
Suffers from a race-condition that manifests itself if the loops is started very shortly before midnight. |