westy032001 has asked for the wisdom of the Perl Monks concerning the following question:
I'm after some advice in avoiding a race condition for reading and possibly modifying a file or an alternate way of doing it.The scenario is this , i have 300 processes connecting to a database at the same time every 15 mins, if these encounter a database error i want them to check a file to see if this error has been encountered before, if it hasn't it adds the error code with a time stamp, if it has been encountered before and the time stamp is greater than an hour ago it will mail the admin. The idea is to avoid getting 300 mails every 15 mins when somthing goes wrong. As far as i can see i need to flock the file then read it, modify if necessary and then unlock, but this causes a bottle neck for my 300 processes is there a better way of doing things ? cheers. I just wanted to thank everybody for taking the time and effort to read, think and post !! thanks.