Gerald Wheeler wrote:
> 
>>>> Rob Dixon <[EMAIL PROTECTED]> 4/3/2008 3:49 PM >>>
> 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.
> 
> ..... Let's assume the transaction completes..........

If you're certain that that's safe, then I can't disagree. But if you
find you're losing records once or twice a year then remember what I
advised.

> 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.
> 
> ... Not necessary ....... w/abv assumption
> 
> 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.
> 
> .... OK... so how would I use the system date "sysdate" to check
> against the date of the records in the file..
> That's what I really need to know how to do..  ............

OK, your program generates lines like

  use these values(5577,'03-Apr-08',2456);

and somewhere it generates the text string '03-Apr-08' to produce those
lines. Suppose it is stored in a variable called $date_string. You need
to read through the file to see if the condition

  $line =~ /$date_string/

or

  index $line, $date_string >= 0

is true for any line in the file.

If the file is expected to become significantly large, then the
File::ReadBackwards module may help you to start reading the file from
the end.

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


Reply via email to