in reply to A flock()alypse now

Color me kooky, but wouldn't it be simplest to open the file in read-write mode?
open(my $FH , '+<', 'the_file')

--
perl -pew "s/\b;([mnst])/'$1/g"

Replies are listed 'Best First'.
Re: Re: A flock()alypse now
by ferrency (Deacon) on Jul 02, 2002 at 18:46 UTC
    Yeah, that would work too :)

    It would be "simplest" if you are familiar with dealing with read/write filehandles. Unfortunately I'm not that familiar with those techniques right now. So it's not "simplest" for me until I learn a bit more.

    Thanks for the alternate solution, and a pointer towards more things to learn.

    Alan

      This approach causes data loss if:

      • the process is terminated for any reason (user intervention, exceeding resource limits, system crash)
      • the disk fills up during execution

      If you don't want to risk losing data, use the sentinel locking approach already mentioned by others in this thread.

      However, if the weaknesses of using only a read/write filehandle aren't a problem for you, you might want to look into FileHandle::Rollback.