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

Hi RhetTbull..
Yes I did post the question again..cuz I didn't know if I had posted it correctly.
I am trying to run the script daily. The script should only show 31 days in the code.
Such as: Today is June 20. I want the 30 days before this date to show up in the output. When its June 21, I want the date at the top to bump off.
I dont' know if I have explained myself properly..but hopefully you can help me out!
~Seema

Replies are listed 'Best First'.
Re: Re: Re: Looping Question....
by RhetTbull (Curate) on Jun 21, 2001 at 01:42 UTC
    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.