How to read and write a file without open file twice? Thanks in advance.

How to read and write a file without open file twice? Thanks in advance.

am 25.09.2007 20:31:56 von Mike

I'd like to code a function that performs read and write a file. The
file is for recording serial no, just a number inside. Each time when
the function is called, the file will be opened, locked, read,
increase the serial no, write, unlocked and closed, then return the
serial no in the end.

Is it possible to do the read and write operations in one file-open
with file lock? Thanks in advance

Re: How to read and write a file without open file twice? Thanks in advance.

am 25.09.2007 20:52:12 von Ben Morrow

Quoth mike :
> I'd like to code a function that performs read and write a file. The
> file is for recording serial no, just a number inside.

perldoc -q increment

Ben

Re: How to read and write a file without open file twice? Thanks in advance.

am 26.09.2007 03:51:27 von Ron Bergin

On Sep 25, 11:31 am, mike wrote:
> I'd like to code a function that performs read and write a file. The
> file is for recording serial no, just a number inside. Each time when
> the function is called, the file will be opened, locked, read,
> increase the serial no, write, unlocked and closed, then return the
> serial no in the end.
>
> Is it possible to do the read and write operations in one file-open
> with file lock? Thanks in advance

use File::CounterFile;
http://search.cpan.org/~gaas/File-CounterFile-1.04/CounterFi le.pm

Re: How to read and write a file without open file twice? Thanks in advance.

am 26.09.2007 20:56:16 von Mike

cool!
Guys thanks a lot.