Seema has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Looping Question....
by virtualsue (Vicar) on Jun 20, 2001 at 22:58 UTC
    Hi Seema,

    Hello.. I am a new member of the Monks. My name is Seema. I am a student at Purdue University. I would love to chit-chat..but if I start...I won't stop. :o

    Be that as it may, I suggest you drop by the Chatterbox soon and discuss what you want with some of the monks, because at almost any time of the day or night you can usually find several reasonably clued-up people to help you. If you talk about what you're looking for in "real time" I think you will get a lot farther than you are by re-posting your question every couple of days. :-)

Re: Looping Question....
by Sifmole (Chaplain) on Jun 20, 2001 at 21:45 UTC
    You really need to explain your question better because it is hard to understand what exactly you are asking... but I am going to give two tries...

    1) If you mean that you need your script to run once a day over 31 days, well then it sounds like you need to check out "cron" on your system -- this is not a Perl specific item.

    2) If you are looking to populate a drop-down list of 31 days from the present, then you might want to check out the Date::Calc library which has some nice date calculation routines. You can search for it on cpan.org.

    Good Luck

      Thanx Sifmole...
      I need to write a script in Perl before I even put it on the Unix machine. The problem is...I didnt' know how to come about this situation. Though I will take a look at: cpan.org. for some clues. Thanx for replying! :o)
      ~Seema
Re: Looping Question....
by dimmesdale (Friar) on Jun 20, 2001 at 21:46 UTC
    If you're on Unix, why not use cron? It seems like the perfect tool for the job. If your server ever went down when you implemented the looping method, you'd have to restart the perl script every time. There's other problems too. Not to mention it would save a lot of programming to the script. Perl's a powerful tool; but you shouldn't use it where other tools can do it better.
      Larry Wall says approvingly that Perl is often used for tasks where it is not the optimal tool. The reason is that programmers are lazy.

      Let's say that Java is really the best tool for doing XML, but I do not know Java, I know Perl. If Perl's XML tools are almost as good as Java, and I can save weeks of learning time by programming my XML in Perl, then I will probably do my XML in Perl even though Java may be better.

      If a pure cron solution requires too much knowledge of Unix internals and a Perl solution requires only Date::Calc and a simple daily cron job, then I say write a Perl script that cron will run daily, and let Date::Calc, which is available from www.cpan.org, do the date calculations.

      Hi Dimmesdale....
      I really appreciate for you replying to me. :o)
      I am on Unix...though I need a Perl script before I even get on the Unix machine. I am not that familiar with this program...but if you say I may need to use cron...well then can you give me some hints on where I may can find how to use this tool?
      Once again...thanx for helping me out! :o) ~Seema
        If you type in 'cron' in the search on this site, there was a discussion on it that may help. Also, on your unix machine, type in 'man cron'(but it sounds like you don't have access to the machine right away, so I'll paste what my man page says, at least some relavent parts)

        I'd check out these manpages also, if you can: at(1), crontab(1), sh(1), queuedefs(4), attributes(5) (they were mentioned at the end of cron. I don't know much specifcially about cron, but you can access some manpages online at: http://www.tac.eu.org/cgi-bin/man-cgi?cron+8 if you don't have access to them. Here's an article thats rather useful, its from O'Reilly: http://www.onlamp.com/pub/a/bsd/2000/09/27/FreeBSD_Basics.html If you need anymore help, you can search the web, or ask someone--lots of people here are proficient with Unix; I'm, however, rather new to it, and only know a little.

        DESCRIPTION The cron command starts a process that executes commands at specified dates and times. Regularly scheduled commands can be specified according to instructions found in crontab files in the directory /var/spool/cron/crontabs. Users can submit their own crontab file using the crontab(1) command. Commands which are to be executed only once may be submitted using the at(1) command.

        cron only examines crontab or at command files during its own process initialization phase and when the crontab or at command is run. This reduces the overhead of checking for new or changed files at regularly scheduled intervals.

        Since cron never exits, it should be executed only once. This is done routinely through /etc/rc2.d/S75cron at system boot time. The file /etc/cron.d/FIFO is used (among other things) as a lock file to prevent the execution of more than one instance of cron .

        cron captures the output of the job's stdout and stderr streams, and, if it is non-empty, mails the output to the user. If the job does not produce output, no mail is sent to the user (unless the job is an at(1) job and the -m option was specified when the job was submitted).

        Setting cron Defaults To keep a log of all actions taken by cron , CRONLOG=YES (by default) must be specified in the /etc/default/cron file. If CRONLOG=NO is specified, no logging is done. Keeping the log is a user configurable option since cron usually creates huge log files.

        The PATH for user cron jobs can be set using PATH= in /etc/default/cron. The PATH for root cron jobs can be set using SUPATH= in /etc/default/cron. The security implica- tions of setting PATH and SUPATH should be carefully con- sidered.

        Example /etc/default/cron file: CRONLOG=YES PATH=/usr/bin:/usr/ucb:

        This example enables logging and sets the default PATH used by non-root jobs to /usr/bin:/usr/ucb:. Root jobs will continue to use /usr/sbin:/usr/bin.

        /etc/cron.d/logchecker is a script that checks to see if the log file has exceeded the system ulimit. If so, the log file is moved to /var/cron/olog. FILES /etc/cron.d main cron directory /etc/cron.d/FIFO used as a lock file /etc/default/cron contains cron default settings /var/cron/log cron history information /var/spool/cron spool area /etc/cron.d/logchecker moves log file to /var/cron/olog if log file exceeds system ulimit. /etc/cron.d/queuedefs queue description file for at , batch , and cron .

Re: Looping Question....
by RhetTbull (Curate) on Jun 20, 2001 at 22:30 UTC
    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.
      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.