| Prev | Perl Notes |
Next |
It's a good idea to flock a file before writing to it. This ensures that multiple processes won't try to write to it simultaneoudly, possibly damaging or garbling the file's contents.
To get exclusive access to a file:
To release exclusive access to a file:
|
open(FILE, ">>../myfile.txt") || &ErrorMessage; flock(FILE, 2); print FILE "I'm adding text to a file.\n"; flock(FILE, 8); close(FILE); sub ErrorMessage { print "Could not open file. It either does not exist or the permissions are wrong\n"; exit; } |
| Prev | Home | Next |