in reply to A flock question

One simple way is to just NOT close your filehandles manually.

Simply let them fall out of scope when you're done with them, and they will close automagically. That way, you can't try to flock a closed filehandle, because you don't have a reference to it.