|
|
Question : file locking
|
|
Could someone give me a way of locking a file so it doesn't get messed up? I need a file locking routine.
|
Answer : file locking
|
|
Assuming 1. You are using perl 2. Your server is unix, or another platform that supports flock then the following code example is a simple perl package.
If your server is NT then I think that flock is not implemented and another technique will have to be used. If you are testing on Personal Web Server then I think flock will give you a run-time error. The approach I use is to provide stub routines with 'flock' commented out when testing on PWS.
---- code example, Locking.pm ---- package Locking; require Exporter;
@ISA = qw(Exporter);
# # File locking routines # @EXPORT = qw();
# # Obtain a file lock on a file # sub lock { my $fid = shift; flock($fid, 2); }
# # Release a file lock on a file # sub unlock { my $fid = shift; flock($fid, 8); } 1; ---- end of example ----
|
|
|
|
|