in reply to How do I lock a file?

Note:

if you

open(FILE, ">testing")
you will truncate the file before you have it locked, this may not be what you want in a production system! Use
open(FILE, ">>testing")
before you get the lock and then truncate() if you want to, er, truncate the file once its locked. Or lock a separate semaphore file who's contents are unimportant.