Next | Lightweight Databases | 31 |
Suppose we are replacing a record with another of exactly the same length
Then we need not rewrite the entire file
For example:
sub uppercase_username { my ($fh, $username) = @_; seek $fh, 0, SEEK_SET; while (<$fh>) { my ($u, $rest) = split /:/, $_, 2; next unless $u eq $username; seek $fh, -length($_), SEEK_CUR; print $fh uc($u); return; } }
We search the file as usual
When we find the record we want, we back up and overwrite it in place
Next | Copyright © 2003 M. J. Dominus |