I have read the excellent tutorial:
But somehow I can't get it to work. For example, here is a little script that (a) opens a file, (b) puts an exclusive lock on it, (c) closes the file (hence in theory releasing the lock), then (d) reopens the file and finally (e) tries to put another exclusive lock on it.
my $fpath = 'blah.dat';
open(FILEHANDLE_1, ">", $fpath);
print "Opened file '$fpath' into FILEHANDLE_1.\n";
print "Put exclusive lock on FILEHANDLE_1\n";
print "Closed FILEHANDLE_1. It should now be possible to put an exclus
+ive lock on file '$fpath'\n";
open(FILEHANDLE_2, ">", $fpath);
print "Opened file '$fpath' into FILEHANDLE_2.\n".
"Will now try to put an exclusive lock on it.\n";
print "Successfully put exclusive lock on FILEHANDLE_2\n";
The problem is that the last line is never printed at all! In other words, the script is not able to secure the second lock, eventhough the first lock should have been released by the closing of FILEHANDLE_1.
What am I doing wrong? Note that I am running this on Windows 7. Could this be a problem with that OS? Does this script run fine on Linux?