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:
Can Anyone Help me???

 



Karthik
Deleted

Nov 28, 2000, 10:38 AM

Post #1 of 2 (360 views)
Can Anyone Help me??? Can't Post

Hi all

I Have a text file which has all enteries each seperated by a tab. I am opening the text file and splitting by tabs abd then displaying it on the cgi page.
I have a text area where the message gets displayed
What I want to do is if i change the text in the text area and if click submit the changed text should be sent back to the text file and it should be change.
If the changed is 20th line of the total 40 lines how to do that

anyone can help me on this?
thanks in advance
Karthik
karthik_9479@yahoo.com



Rivotti
User

Dec 12, 2000, 10:11 AM

Post #2 of 2 (359 views)
Re: Can Anyone Help me??? [In reply to] Can't Post

Hi Karthik,

Let me se if I understood well:
You want to replace the data in the text file whit the new submited data, correct?

Let's imagine your text file looks like:
Name\tPhone\tText\n

In your cgi file:

# get the form param
$name = param('name');
$phone = param('phone');
$text = param('text');

# Now open your text file
open(INFILE,"<$your_text_file") || die "Arrgh!";

# For each line read...
while(<INFILE>) {
chomp $_; # get rid of \n in the end of each line

# Get each field and assign them to a variable
($old_name,$old_phone,$text) = split(/\t/,$_);

# Compare $old_name with $name*
if ($old_name eq $name) { # if its equal...
$new_data .= "$name\t$phone\t$text\n";
}
else { # ...
$new_data .= "$old_name\t$old_phone\t$old_text\n";
}
}
close(INFILE);

# Now save the data again
open(OUTFILE,">$your_text_file") || die "Arrgh!";
print OUTFILE $new_data;
close(OUTFILE);

* this assumes that you dont have equal names. You should use an id number or something that have no duplicates


 
 


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

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