in reply to updating/modifying line in a file
However, if you are reading and writing a plain text file, and don't want to wire it up through DBI, you could also grep on $user to find your line, then use something like:my $sql = "UPDATE tablename SET bandwidth = bandwidth + ? WHERE user = + ?"; my $sth = $dbh->prepare($sql); my $sth->execute($newtraffic,$user);
then you can open two file handles, one for reading and one for writing, read the data from the original file, writing it to the new file, using the code above wrapped in a conditional checking for your $user (if(m/$user/){}), to massage it as it goes by.my @user_fields = split /:/,$_; $user_fields[2] = $user_fields[2] + $newtraffic; my $newline = $user_fields[0].':'.$user_fields[1].':'.$user_fields[2];
-- Hugh
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: updating/modifying line in a file
by bran4ever (Novice) on Jun 04, 2006 at 07:58 UTC |