in reply to Re: Re: Looping Question....
in thread Looping Question....

I believe the following code will do what you want. Note, I put a loop in the code so that it would execute every day but this is probably not what you want. If you need to execute a script (or any program) every day, then you want to learn about "cron" if you're on a unix machine or "at" if you're on a WindowsNT/2000 machine. To learn more about cron, type "man cron" and "man crontab" at a unix shell prompt. To learn more about "at" type "at /?" at a Windows Command Prompt.

Here's a simple example using Date::Calc that will print out a list of dates from today to 31 days in the past.

#!/bin/perl use warnings; use strict; use Date::Calc qw( Delta_Days Add_Delta_Days Date_to_Text Today); #create an infinite loop, probably not what you really want! while(1) { #get today's date my @today = Today(); my $i = 31; #how many days do you want to go back? my @datelist; #the list of dates #create the list of dates while ($i-- > 0 ) { #subtract $i days from today's date my @date = Add_Delta_Days(@today, -$i); # [ @date ] creates an array ref push (@datelist, [ @date ]); } #datelist is now an array of array refs (in the Date::Calc for +mat) #print out the list foreach my $date (@datelist) { #since @datelist is really an array of array refs, #we dereference it using: @{$date} print Date_to_Text(@{$date}),"\n"; } #sleep for a day (1 day = 86400 seconds) sleep(86400); }
Regards,
Rhet

PS. -- since you're new here, I highly recommend taking a look at turnstep's guide to the monastery.