Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Do I need to use sysopen for countfile locking?

by fraktalisman (Hermit)
on Aug 29, 2003 at 13:27 UTC ( #287642=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Mysterious Disapperance of file contents
in thread Mysterious Disapperance of file contents

I don't quite understand why to use sysopen. The same trouble Gorby has now, I had about two years ago (CGI counter resets for no obvious reason). Later I modified my counting system to something similar to your example. It obviously works, but if it's "bad" code I surely want to understand why and improve it. Here it is:
#! /usr/bin/perl use Fcntl ':flock'; open(Z,"+<count.txt")||&neu; flock(Z,LOCK_EX); $z=<Z>; $z++; seek (Z,0,0); print Z "$z\n"; flock(Z,LOCK_UN); close(Z); print "Status: 204 No Response\n\n"; exit(0); sub neu {open(Z,">count.txt"); print Z "0\n"; close(Z); open(Z,"+<coun +t.txt");}

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://287642]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2020-05-31 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (173 votes). Check out past polls.

    Notices?