use strict; use warnings; use Class::Date qw(:errors date localdate gmdate now -DateParse -EnvC); my $start = date now; #start date of the program running in format YYYY-MM-DD HH:MM:SS my @split = split(/ /, $start); #get just the Year/Month/Day open (FILE, ">>/my/directory/logfile-$split[0]"); #open our daily logfile print FILE "$start\n"; sub dailyTask{ my $now = date now; #Get our current time my @split = split(/ /, $now); close FILE; #close the existing daily file, in production this will zip it into a running archive of daily files open (FILE, ">>/my/directory/logfile-$split[0]"); #open our new daily file } while(1){ my $test = date now; #date when we start the loop print "Start: $start\n"; #print our values, so I can see print "Test: $test\n"; my $soon = $start + '1D'; #Adds 1 day onto the start date print "Soon: $soon\n"; print FILE "$test\n"; if($soon < $test){#Check if I've passed our start + 1 day print "It's soon, now!\n"; #If so, print our value $start = $test; #update the new start time dailyTask(); } sleep(86400); #sleep until tomorrow }