
monocle
User
May 24, 2000, 8:19 AM
Post #2 of 6
(584 views)
|
I don't know if there is an more eligant way of doing this but I think this should work. If the new line is in fact a "new Line", it will be appended to the end of the file. I assumed a two things: 1) your data file is a ":" delimited txt file. 2) your four data fields are coming from a form. -adjust script accordingly- <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #Open File And Read All Lines open(LINES,"$datafile"); flock(LINES, 2); @items = <LINES>; flock(LINES, 8); close(LINES); #Compare Data Fields Line By Line $line_is_there = "0"; foreach (@items) { ($data_field_1, $data_field_2, $data_field_3, $data_field_4) = split(/\:/,$_); if ($data_field_1 eq "$FORM{'data_field_1'}") { $line_is_there = "1"; last; } } #Open File To Append New Line if ($line_is_there == "0") { open(LINES,">>$datafile"); flock(LINES, 2); print LINES "$FORM{'data_field_1'}:$FORM{'data_field_2'}:$FORM{'data_field_3'}:$FORM{'data_field_4'}\n"; flock(LINES, 8); close(LINES); } </pre><HR></BLOCKQUOTE> Right before posting this I questioned whether I had misunderstood your post, but I decided to reply anyway. Hope this helps. If not, oops on my part. Monocle Hear techno music by Monocle here: http://www.mp3.com/monocle
|