tobold.org

correct • elegant • free

△ comp.lang.perl △

◅ How do I access a DBM as read-only

2 simple questions about fork ▻

Open for Read & Write? ... and FLOCK

In article <32DBB984.5F28@netct.com>, Peter  <peter@netct.com> wrote:
>But I can't get the file to open correctly... because if I open the way
>I have it below, it reads in the digit, and saves the new number on a
>line below the existing value.

Of course, because you've only made one call to open so you only have a
single pointer into the file for both reads and writes.  You could call
open twice, once for reading and once for writing.  Or you could use
seek to rewind the file pointer before you write to it.

>Part II: I've read the Perl docs for info on flock, but I'm not 100%
>sure how it works, once the file is locked by the script, if another web
>user-person tries to call the script, will it wait at the flock(COUNT,2)
>line until the file is unlocked?

Yes.

It looks like you're trying to implement a persistent counter.  Have you
looked at the File::CounterFile module, which does exactly this?

Tim.
--
Tim Goodwin   | "A language needs both intestines and guts." -- Larry Wall

Original headers:

From: tim@pipex.net (Tim Goodwin)
Newsgroups: comp.lang.perl.misc
Subject: Re: Open for Read & Write? ... and FLOCK
Date: 15 Jan 1997 14:47:57 GMT
Organization: UUNET PIPEX
Message-ID: <5biqmt$aa5@join.news.pipex.net>
References: <32DBB984.5F28@netct.com>

△ comp.lang.perl △

◅ How do I access a DBM as read-only

2 simple questions about fork ▻