in reply to Looping Question....

This is the exact same question that you posted three days ago here. It sounds to me like you didn't get the answer you were looking for so you created a whole new node and asked again. The reason you may not be getting the answer you want is that your question makes no sense. I've read it several times and I can't figure out what the heck you're trying to do. Is this a cron job (i.e. are you trying to run a script every 31 days?), are you trying to populate a list with some dates? Please provide more information (in an update to this post, not a whole new node). This also sounds a bit like homework to me... At any rate, I'm sure you'll get more help if you provide more details about what you're trying to do.

Replies are listed 'Best First'.
Re: Re: Looping Question....
by Seema (Novice) on Jun 20, 2001 at 23:04 UTC
    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
      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.