
perlkid
stranger
Jun 25, 2000, 10:41 AM
Post #2 of 2
(1009 views)
|
Re: Deleting entries in multi flat-file DBs
[In reply to]
|
Can't Post
|
|
Try this, Open the data file(s) and store them into arrays. After reading all of the data bases close all the opened files. Then use a foreach condition on the arrays and use the next; function to get rid of the line you don't want. That was a confusing description but it's only meant to describe the following code. open(file1, "</path/file.db") @all=<file1>; close(file1) Repeat this for as many data files you need to remove the line from. open(file2, "</path/file2.db") @all2=<file2>; close(file2) I'll stop at two but if you have more then continue. Now you need to remove the lines with the information inputed into a form. open the same data base that the information stored in @all came from. open(Write, ">/path/file.db"); foreach $line (@all) { @fields=split(/\|/, $line); # I suppose your using a pipe to separate your fields if ($field[0] eq "$form{'address'}") # $field[0] is the field that contains the data you are looking to get rid of. { next; } # print the filtered data back to the file it came from in the same order print Write "$field[0]|$field[1]|so on and so on"; } close(Write); also do this for the second array, @all2. That's it. Do you get it? Ok, Hope that helped? perlkid ------------------ perlkid
|