in reply to updating/modifying line in a file
There may be some slick way to do this with only one file open overwriting only the line you are concerned with, but it is not apparent to me at this late hour. And generally I am of the mind that it is more important to ensure that a program works than that it is fast or fancy.open(DB_RESULT,">/path/to/result/db/file"); open(DB_SRC,"/path/to/source/db/file"); while (<DB_SRC>){ if($_ ~= /$user/){ my @user_fields = split /:/,$_; $user_fields[2] = $user_fields[2] + $newtraffic; my $newline = $user_fields[0].':'.$user_fields[1].':'.$user_fields +[2]; print DB_RESULT, $newline; } else { print DB_RESULT, $_; } } close(DB_SRC); close(DB_RESULT); my $result = `mv /path/to/result/db/file /path/to/source/db/file`;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: updating/modifying line in a file
by bran4ever (Novice) on Jun 04, 2006 at 08:26 UTC |