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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |