Use a database. I'm serious. This requirement is impossible to implement using files. You can use lock-files and the like, but that means you're just queueing up the changes to be done serially instead of parallely. (Not to mention that it's REALLY easy to screw up lockfiles and have everything go to hell in a handbasket mighty quick.)
Lots of people seem hell-bent on using full-blown RDBMS's these days even for the most simple things. File locking isn't black magic; see this article about semaphore files. Yes, there could be a queue, but if the running time of a script is short it probably isn't a problem.

If certain information is always on a specific line, use Tie::File. With this module you can access a normal file like an array ($line[0] is line 1, $line[1] is line 2, etc). I think it also does locking, but you'll have to experiment with that.

And if the problem is small, and a database is called for, use DBD::SQLite (the complete database is included in the module source) and DBI. This lightweight database uses a single file to store information, so you don't have to do a system-wide, full-blown MySQL or PostgreSQL installation.

Arjen

Update: Using Tie::File is even a good idea if information isn't always on the same line. If you change a line (array element), then the file automatically gets rewritten. So, you don't have to read in the file, search, replace, and write the file but just change an array element and the rest goes automagically.


In reply to Re: Re: Modifying lines of text by Aragorn
in thread Modifying lines of text by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.