It's unclear whether your solution MUST be all-perl or not.
If NOT all-perl, you can do something "at the end of every day" and "at teh end of every week" (the latter just means end of Sunday) using your system's scheduler (cron
on Unix/Linux/MacOS, AT
pr Windows Scheduler on Windows).
For end of month, you can run the script every day but at the beginning, quit if not end of month. The logic for both end of month (and end of week as a bonus) would be using something like:
use Time::Local qw ( timelocal_nocheck );
my @time_data = localtime() ;
my $current_dom = $time_data[3];
my $current_dow = $time_data[6];
$time_data[4]++; # Next month.
$time_data[3] = 0; # Last day of previous month.
@time_data = localtime ( timelocal_nocheck ( @time_data ) );
if ($current_dom == $time_data[3]) {
# Do end of month processing
}
if ($current_dow == 0) { # Sunday
# Do end of week processing
}
Hat tip: http://www.perlmonks.org/?node_id=418897