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:
writing to a file

 



jacksonpt
Deleted

Dec 4, 2000, 12:28 PM

Post #1 of 2 (314 views)
writing to a file Can't Post

I have a database file with fields delimited by double semicolons (;;). I am working on a script that will use HTML forms to allow a user to edit records within the file. The file is fed into an array line-by-line, with each element of the array holding a single field from the current record. Here's the code:
while ($line = <datafile> ) {
@array = split (/;;/, $line);
*work with each record*
}

The file has a specific order that needs to be maintained.

So, here are my questions. First, is there a way to read though the file, and when specific conditions are met (i.e. the correct record is found), overwrite a portion of the record, then continue reading the file. Something like this:
while ($line = <datafile> ) {
@array = split (/;;/, $line);
if ($array[3] eq "yes") {
$array[3] = "no";
write to file new value for $array[3]
}
}
now continue reading file


My second question is this: The user uses an HTML for to locate the record they want to delete. Search the file for that record:
while ($line = <datafile> ) {
@array = split (/;;/, $line);
if ($array[0] eq *selected record ID*) {
*delete record*
}
}
continue reading the file


Thanks for any insight.
-Jackson


sleuth
Enthusiast / Moderator

Dec 5, 2000, 10:49 AM

Post #2 of 2 (314 views)
Re: writing to a file [In reply to] Can't Post

 
Sorry, bit of a more complex trick needed for it. heh, it's not hard though, easy to catch on, you can read all about it here, I explained how to do it step by step to dslever here:
http://www.perlguru.com/forum/Forum7/HTML/000435.shtml

Sleuth

 
 


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

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