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.


In reply to Re: Re: Re: Looping Question.... by RhetTbull
in thread Looping Question.... by Seema

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.