Essentially, what I'm not sure if is whether or not the <FILE> file handle will (a) be passed to the called subroutine, and (b) whether the newly defined file handle will persist outside the scope of the subroutine. What is marked above is the essence of what I'm trying to accomplish (obviously with all the additional logic stripped out, for readability). Does anyone have any suggestions, or should the code work as written? Thank you.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 YYY +Y-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 logf +ile 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 wil +l zip it into a running archive of daily files open (FILE, ">>/my/directory/logfile-$split[0]"); #open our new da +ily 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 }
In reply to Scope of Filehandle inside Subroutine? by SituationSoap
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |