Hi all, I'm writing an app which uses a flat file to store a *short* list of simple key/value pairs. However having read the flock() man page, I'm unsure about whether I need to seek() in cases where I'm not merely appending to the file (such as when deleting a record).
sub Delete_Record { my ($file, $key, $value, @array) = @_; open(OUT, ">$file"); flock(OUT, LOCK_EX); seek(OUT, 0, 0); # Should I do this? foreach (@array) { # FYI: $/ = "\n" seek(OUT, 0, 2); # Or perhaps this? print OUT $_ unless ( m/^$key\s+$value$/ ); } flock(OUT, LOCK_UN); close(OUT); } Btw, the above code is just to illustrate the question, thus no error checking and so forth. -- ===================== Shaun Fryer ===================== http://sourcery.ca/ ph: 905-529-0591 ===================== Science is like sex: occasionally something useful comes out of it, but that's not why we do it. -: Richard Feynmann
pgp00000.pgp
Description: PGP signature