in reply to Re: Re: writing to the top of a file
in thread writing to the top of a file

1. Every time this issue comes up, I tend to favor using a semaphore file. Provided that we're talking about a file that is only updated by perl processes, and that all these processes follow the same procedure in terms of "asking" for access to update the file, then there's no problem. (Find an example of a semaphore file module here, which includes a reference to a very good article on locking any shared resource.)

2. If the file size happens to be equal to or greater than the available free space on a drive, any solution for trying to "prepend" new data at the top of a file will overfill the file system, because you need to write the new file before you can delete the old one. That's a very good reason to avoid trying to update a file this way. Appending to a file will only fail if the amount of new data being added exceeds the amount of available free space on the drive.

You're wise to be curious about these issues.

  • Comment on Re: Re: Re: writing to the top of a file