| Next | Lightweight Databases | 13 |
This is something like what -i does:
sub delete_user {
my ($file, $target_user) = @_;
open my $rfh, "<", $file or die ...;
rename $file, "$file.bak" or die ...;
open my $wfh, ">", $file or die ...;
while (<$rfh>) {
my ($user) = split /:/;
print $wfh unless $user eq $target_user;
}
close $rfh; close $wfh;
}
The problem is that the rename is too soon
We shouldn't replace the old contents with new so early
We should wait until the complete new file is in place
| Next | ![]() |
Copyright © 2003 M. J. Dominus |