Jun 9, 2001, 4:17 PM
Post #4 of 6
> If i have - for example - a web counter script - when
> i'm accessing a file and incrementing the number within
> it, would i need to lock the file to prevent multiple
> users initiating the script and overwriting the data?
> If so, then would it still register them running the
Yes. Place an exclusive lock on the file. This ensures that only one process at a time can write to the file.
Any other process(es) coming along wanting to modify the file have to wait until the lock is released. You can
read more here...
randor, your code fails because...
Can't modify scalar safe chop in scalar assignment...etc.
chomp ($number) = <CART_ID>;
You need to...
...which will give $number a chance to be assigned a value before you chomp() it.
chomp( $number = <CART_ID> );
Also, you're escaping the escape for the newline when you print the number back to the file, so the actual characters \n are written instead.