Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I read the same text file from many pages, but only for read. Must the text file always be locked for security?

Originally posted as a Categorized Question.

  • Comment on Is it always necessary to lock a text file?

Replies are listed 'Best First'.
Re: Is it always necessary to lock a text file?
by lhoward (Vicar) on Jun 24, 2000 at 16:52 UTC
    If you are only reading a file, you do not need to lock it. Locks are only important when writing to the file is involved.
Re: Is it always necessary to lock a text file?
by Anonymous Monk on Dec 18, 2000 at 21:38 UTC
    Locking the file is not necessary when reading only, and when writing only if there is a possibility of more than one write happening simultaneously (as in the case of a cgi script or multi-user environment) If you are the only person using your script, or if it is a standalone script that only runs on one machine, locking is not necessary.
Re: Is it always necessary to lock a text file?
by I0 (Priest) on Dec 18, 2000 at 22:28 UTC
    If the file is being written while you are reading, it may be neccesary to LOCK_SH to avoid reading an inconsistent partial update.