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:
Delete multiple lines from flat text file (Newbie)

 



biggles2k
New User

Dec 1, 2002, 9:37 AM

Post #1 of 4 (484 views)
Delete multiple lines from flat text file (Newbie) Can't Post



I have a script which returns an html page displaying the contents of a flat text file (list of names and emails) each line has a checkbox, this is passed to a second script which opens the flat file and prints the name and email address of the corresponding "checked" checkbox. I would like to have the script print the "unchecked" boxes so that the selected entries will be deleted from the file.

Thanks in advance for any assistance.

Code to display html page

foreach $file (@data)
{

($email,$name)=split(/\|/,$file);



print "<TR><TD ALIGN=\"CENTER\" WIDTH=\"6%\" BGCOLOR=\"#7974A2\" VALIGN=\"MIDDLE\">"
;

print
"<FORM method=\"post\" action=\"thescript.pl\">"
;

print
"<input type=checkbox name=\"action\" value=\"$email\|$name\">"
;

print "<TD ALIGN=\"LEFT\" WIDTH=\"47%\" BGCOLOR=\"#cccccc\" VALIGN=\"MIDDLE\">"
;

print
" $name&nbsp</TD>"
;

print
"<TD ALIGN=\"LEFT\" WIDTH=\"47%\" BGCOLOR=\"#cccccc\" VALIGN=\"MIDDLE\">"
;

print
"<A HREF=\"mailto:$u_email\">$email</A></TD>"
;

print "</FORM >";

}

Code to write to file

my @data = param(
'action');

my $subs =
"/subscribers.txt";


print "Content-type: text/html\n\n";

print
"<H3>These items Selected</H3> "
;

print
"@data"
;



open (DATA,
">$subs") || die "cant open $subs\n"
;

print DATA @data;

close (DATA);



thodi
stranger

Dec 1, 2002, 2:18 PM

Post #2 of 4 (479 views)
Re: [biggles2k] Delete multiple lines from flat text file (Newbie) [In reply to] Can't Post

So your problem ist how to delete lines from a file? Wow, that's a new idea. http://perlguru.com/gforum.cgi?do=search_results&search_forum=all&search_string=delete+line+from+file&search_type=AND&search_fields=sb&search_time=&search_user_username=&mh=25


davorg
Thaumaturge / Moderator

Dec 2, 2002, 12:02 AM

Post #3 of 4 (472 views)
Re: [biggles2k] Delete multiple lines from flat text file (Newbie) [In reply to] Can't Post

This sounds like it might be a FAQ

How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


biggles2k
New User

Dec 2, 2002, 6:08 PM

Post #4 of 4 (455 views)
Re: [davorg] Delete multiple lines from flat text file (Newbie) [In reply to] Can't Post

Ok, great suggestions they really helped, but my problem now is, the script overwites the file with the values of the selected checkboxes so instead of removing these lines, they are saved and all else is deleted.

All help is greatly appreciated.

 
 


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

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