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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://287642]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-29 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found