in reply to Re: TIMTOWTDI - a counter
in thread TIMTOWTDI - a counter

I'd

Care to translate it into code? :)

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Re: TIMTOWTDI - a counter
by Anonymous Monk on May 26, 2002 at 19:29 UTC
    Sorry. I meant those suggestions to be pretty much straighforward modifications or additions to your code, not anything entirely different.
    use Fcntl qw/:DEFAULT :flock/; sub counter { my $file = shift; sysopen(COUNTER, $file, O_RDWR|O_CREAT) || warn $! && return; flock(COUNTER,LOCK_EX) || warn $! && return; my $count = <COUNTER> || 0; seek(COUNTER,0,0) || warn $! && return; truncate(COUNTER,0) || warn $! && return; print(COUNTER $count + 1, "\n") || warn $! && return; close(COUNTER) || warn $! && return; return $count + 1; }