The error that you have is very often seen as a result of a race condition when your open mode is
+> or if locking did not work. It should not happen if your mode is
+< and you check for locking (which you do).
Therefore it is odd that you are seeing the problem.
But the fact that this code is clearly inline in the top of a script is suspicious. I would strongly suggest that you look through all of your scripts which access counter.txt and see if any of them has omitted locking or has the wrong
open mode. I would further suggest that, rather than write the same locking code in each script, you write a function in a library and then call that function from everywhere. This reduces code duplication, and keeps you from having to look for problems like this in lots of places to make sure that you caught the last place that the bug is to be found.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.