http://qs321.pair.com?node_id=888275


in reply to How to get after 4 and 5 days date from today date

sleep (5*24*60*60); my $after5date = localtime(time); print $after5date; sleep (4*24*60*60); my $after4days = localtime(time); print $after4days;
NB: sorry, this is a joke

Replies are listed 'Best First'.
Re^2: How to get after 4 and 5 days date from today date
by ikegami (Patriarch) on Feb 15, 2011 at 16:11 UTC

    Not all days have 24 hours. Fix below. This will also give you the answer up to 23.5 hours sooner.

    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.