if you look at the code you may wonder why on earth i hard code the file names for every file that i write to.perhaps your thinking is this programmer on drugs or just stupid.
well the answer is neither!
the people who run tripod think programers are so stupid they can't tie their shoe laces. so at tripod when every they run a perl program for you the folks at tripod force it to be run with the "-T" option. the "-T" stands for tainted, and when its used it won't let you open files for output using variable names. ie: you have to hard code the stinking file name which is a royal pain in the ass.
the "-T" option was invented by some drug crazed idiot who though it would prevent hackers from doing stuff. well it does. but it also prevents programmers from doing stuff.
The flock'ing code doesn't seem to work
I call the program sleep_j.pl which flock's the file and then goes to sleep for 60 seconds. This should keep out all other programs.Then I run the program email_add_join_copwatch.pl. If the flock'ing is working the program should hang till the sleep program finishes its 60 seconds of sleeping. But it DOESN'T. Which means the flock'ing isnt working.
When FLOCK() is called with the proper parameters it returns with a value of 1 or TRUE which means it is working.
When I run two programs and FLOCK() works in both of them and returns a value of 1 or TRUE the 2nd program should hang or block and WAIT according to the FLOCK() documenation. But it doesn't. I tried or'ing in the WAIT bit assuming the documentation was wrong and it works backwards. But this this doesn't fix things. I suspect FLOCK() isn't supported on the tripod site. Perhaps tripod runs on WINDOWZ softare.
When I call FLOCK() with a invalid paramater it returns a value of 0 or FALSE which means the FLOCK() failed. So FLOCK() is smart enough to know if it was called with the correct parameters.
So based on this it looks like I am calling FLOCK() properly. And perhaps there is some other reason why the FLOCK() is failing.
Why! Perhaps tripod is on Windows machines which don't support flock()???
FLock stands for File LOCK and is used to make sure that when two or more people use the code at the same time that they don't overwrite each others data.
Even if the flock() isn't working it should only be a problem when two or more people use the code at the same time.
Flock(file,command):
LOCK_SH (1)seek():
Establishes a shared lock on the file (read lock).
LOCK_EX (2)
Establishes an exclusive lock on the file (write lock).
LOCK_UN (8)
Removes a lock from the file.
LOCK_NB (4)
Prevents flock from blocking while trying to establish a lock with LOCK_SH or LOCK_EX and instructs it to return immediately. LOCK_NB must be ored with the other operation as an expression for the operation argument, i.e., (LOCK_EX | LOCK_NB).
seek
seek(filehandle, offset, whence)
Positions the file pointer for filehandle, just like the fseek(3) call of standard I/O. The first position in a file is at offset 0, not offset 1, and offsets refer to byte positions, not line numbers. The function returns 1 upon success, 0 otherwise. For handiness, the function can calculate offsets from various file positions for you. The value of whence specifies which of three file positions your offset is relative to: 0, the beginning of the file; 1, the current position in the file; or 2, the end of the file. offset may be negative for a whence of 1 or 2.