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

Being retarded I'll ask a silly question or two:

1) as coec said what about multiple instances of the script running. How best stop data loss? Is Perl's advisory locking flock sufficient?

2) if the file gets really large, broquaints solution could (potentially) fill a file ssytem resouce.

I am very new to Perl Monks and Perl and most other things IT. Just curious about these issues.

retard

Replies are listed 'Best First'.
Re: Re: Re: writing to the top of a file
by graff (Chancellor) on May 20, 2004 at 04:11 UTC
    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.