Rob Dixon wrote: > Mathew Snyder wrote: >> Tom Phoenix wrote: >>> On 2/9/07, Mathew <[EMAIL PROTECTED]> wrote: >>> >>>> I'm running this as a cron job 1 minute after midnight on Saturday >>>> nights (Sunday morning) so as to cover all of Saturday back through the >>>> previous Sunday. Does your suggestion mean I'd have to run it late >>>> Sunday night in order for it to cover Saturday back to the previous >>>> Sunday (since the timestamp would be 24 hours ago)? >>> The idea is to run it sometime in the first hour (or so) of the day on >>> Sunday. (Lots of cron tasks get scheduled for that first minute of the >>> day or week; it's probably more reliable to run it a few minutes >>> later.) When it runs, it needs to determine the previous day's date >>> (right?). It can do that by giving localtime an adjusted time value, >>> instead of the current time. >>> >>>> I'm also guessing that this corrects the problem I mentioned regarding >>>> skipping the 31st of Jan which was in the middle of the week. Is > that a >>>> good assumption? >>> Well, that problem came from your own date-handling code (yes?); if >>> you use Perl's code (i.e., the localtime function), you shouldn't have >>> those kinds of bugs. Unless I've misunderstood you. >>> >>> Good luck with it! >>> >>> --Tom Phoenix >>> Stonehenge Perl Training >>> >> >> Sorry to rehash this but from this: >> >> #!/usr/bin/perl >> >> use warnings; >> use strict; >> >> my @date = (localtime (time - (24*60*60)))[3..5]; >> >> foreach my $i (@date) { >> print $i . "\n"; >> } >> >> exit; >> >> I get this: >> >> 10 >> 1 >> 107 >> >> >> I still have to add 1 to the month. Is that right? Also, the year > still needs >> to be fixed by adding 1900 but from what I've read that is due to the way >> computers work and not necessarily because of Perl. > > You're misunderstanding what Tom wrote. He's saying that, rather than > trying to > do arithmetic on a day/month/year structure, you can just add mutiples of a > day's worth of seconds to the time that localtime() processes. I've written > below the equivalent to your original program which pushes the day, > month and > year values onto their own arrays for the preceding seven days. I hope this > makes it clearer. > > Rob > > > use strict; > use warnings; > > my (@days, @months, @years); > > my $time = time; > > for (1 .. 7) { > > $time -= 24*60*60; > > my @date = (localtime($time))[3..5]; > > push @days, $date[0]; > push @months, $date[1] + 1; > push @years, $date[2] + 1900; > } >
Ooohhh...ok. So if I had just looped it I would have had an entire weeks worth of dates. Dang it. Sometimes I wonder if I'm cut out to be a programmer. Thanks. Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/