in reply to To flock or lock??

Personally, for any bit of file handling code I write, I always get a shared lock if I'm reading it, and an exclusive lock if I'm writing/appending (unless this is just a quickie script that will never be used a second time). This does introduce a performance hit, but if that becomes an issue, it's a matter of commenting out one line.

I do this mostly as a means of covering myself. If someone else writes a program that also works with this file, and this file gets messed up because they didn't lock it, I can say: "I did my part. If you didn't do yours, that's not my fault."

----
Reinvent a rounder wheel.

Note: All code is untested, unless otherwise stated