CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Deleting entries in multi flat-file DBs

 



jr
Novice

Jun 22, 2000, 1:12 PM

Post #1 of 2 (553 views)
Deleting entries in multi flat-file DBs Can't Post

I have a listing of multiple flat-file databases all stored under one directory (such as:
$directory/file1.list.cgi
$directory/filemore.list.cgi
etc.)

The directory stores different information for an automatic mailing list, in the format of:
name|email address
another name|another email address

I want to be able to run one script that opens up all of these files and then deletes a specific line that matches an inputted email address, but leaves the other lines untouched UNLESS they match the pattern you submit through the form.

Can anyone point me in the right direction? I just can't quite get it down right...


perlkid
stranger

Jun 25, 2000, 10:41 AM

Post #2 of 2 (553 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? Smile

perlkid

------------------
perlkid


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives