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: Beginner:
Delete Line?

 



xMattHawkx
stranger

May 13, 2001, 8:55 AM

Post #1 of 3 (1148 views)
Delete Line? Can't Post

Is there a way to delete a single line from a file if a line number is specified?

Lets say the file looks like this:

1|Bob|bob@bob.com
4|Matt|Matt@matt.com
2|John|john@john.com
3|Bill|Bill@bill.com

How could I delete line 2 (4|Matt|Matt@matt.com) from the file?

Thanks for your time!

:// xMattHawkx



wickedxter
User

May 13, 2001, 10:02 AM

Post #2 of 3 (1144 views)
Re: Delete Line? [In reply to] Can't Post

$linetochange = 4;

open(FILE,"change.txt");
@data = <FILE>;
close(FILE);
print "Content-type: text/html\n\n";
open(FILE,">change.txt");
foreach $line (@data) {
($num, $word) = split(/\|/, $line);
if ($num == $linetochange ) {
print FILE "$num|changed|\n";
}
else {
print FILE "$num|$word|\n";
}
}
close(FILE);

thats what i use to change things with in a file.



japhy
Enthusiast

May 14, 2001, 7:06 AM

Post #3 of 3 (1129 views)
Re: Delete Line? [In reply to] Can't Post

Please read the FAQ. "How do I delete a line?" is one of the questions. We have it in the FAQ forum.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


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

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