Gerald Wheeler wrote:
> Need some assistance:
> A script that writes (will usually appends) 8 records
> (rows/lines/whatever) to a flat file
> problem:
>       If there are NO records with the date (date format: 03-Apr-08)
> of the "incoming data" I want to write/append these records to the file
>       If there are existing records with the date (03-Apr-08) of the
> "incoming data" I want to simply exit the script.
>       The script will run multiple times per day, everyday.
> Sample input (8 records)
> "use these values(1234,'03-Apr-08',1234.56);"
> "use these values(1357,'03-Apr-08',1234);"
> "use these values(2468,'03-Apr-08',333666);"
> "use these values(4567,'03-Apr-08',3456);"
> "use these values(2233,'03-Apr-08',3234.56);"
> "use these values(3356,'03-Apr-08',2234);"
> "use these values(5577,'03-Apr-08',633666);"
> "use these values(5577,'03-Apr-08',2456);"
> 
> Using the date as the determining factor as to write/append or simply
> exit the script because the data already exist from a prior run, how is
> the best way to do this and how do I easily compare dates in Perl

If this data is at all critical then you need to account for the
possibility that the program fails before it completes. For instance, if
only the first line of many with the new date is appended and then the
program dies, all subsequent runs will find a record with the current
date and assume it is complete.

Does your data format support comments? If so then writing a comment
line at the end of each run's additions will show that it has completed.
If a later run finds that there is no closing comment then it should
delete all entries for that date and try to rewrite them.

There is no need to compare dates. Your program is already generating a
date string, and it can simply check to see if the tail records of the
data file contain that string.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to