flock (DATAFILEIN, 8);
if (open(DATAFILEOUT, ">$catagory.dat") ) {
flock (DATAFILEOUT, 2);
Here you unlock the file, then open and clobber it, then lock it again. How do you know some other process didn't add new data to the file in between? Two better solutions would be:
- Open the file read-write, with "+<$category.dat". Do all your reading, seek back to the beginning, truncate the file, and then write the new data back out.
- Use a separate lock file, ">$category.lck". Don't unlock that file until your update is finished. With this solution, you can write the data back to a temporary file, $category.tmp, then rename it to $category.dat. That saves memory, because you don't need to store everything in @temp, but maybe your application doesn't have enough data for that to matter much.
You shouldn't have any trouble getting the viewer to expire old data. You might want to read in all the data and do the necessary expirations first (the code for this part could be reused), and then check to see if there's anything left to display.
Update: It would be a good idea to have the viewer get a read-lock on the file, too.
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.