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

Hello, I have a script on a cron which reads a table and then does a few calculations and prints the output to a log file. Now my problem is when I run the script just once, it gives the desired output. But when I put the job on a cron, the END stmnt of the script is repeated numerous times. Now, I need the log to have only one END statement at the bottom, but the output of the cronjob should be appended above the END statement, IN THE LOG ie....the END is read, only once and the data in printed numerous times above it.Here is my code:-
foreach $x (@x) { printf "%7d",$x; } ###############END OF FILE########### END { foreach $y(@y) { printf "%7s",$y; } } }
ANY SUGGESTIONS ARE APPRECIATED :-)

Updated - Steve_p added code tags

janitored by ybiC: lc title to avoid shouting in this here our fine Monastery

Replies are listed 'Best First'.
Re: Output from a cron job should...
by herveus (Prior) on May 13, 2004 at 11:39 UTC
    Howdy!

    If I read you correctly (and CODE tags around the code would make that so much easier), you want the log file to have only one set of output from the END block regardless of the number of runs accumulated there.

    That's not going to be easy, especially if you are just printing to STDOUT, since you won't be able to seek to the right place to insert the desired output, and all that. Perhaps you need to have two output files. One for the first part, that you keep appending to, and another for the "END" data that you overwrite each time.

    yours,
    Michael
Re: Output from a cron job should...
by nimdokk (Vicar) on May 13, 2004 at 12:32 UTC
    Unless there is more to your script than what you are showing, you have an unmatched right curly brace. At a guess, there might be something with how you are opening the log file but without seeing more of the code, it is hard to say.
      Nimdokk, There is more to the code than what I have, and I have taken care of the curly braces too....The thing is the code works just fine when I run it from cmd line....the problem comes up when I try to put it on a cron... herveose...... I understand what you are saying about using 2 files....but we already hav a kron job which uses about 4 files...we want to put this job in 1 file.