I have this script I've been working on that can be - in theory - embedded in an xssi call that recognizes the DOCUMENT_URI, queries that against a flatfile list and increases a count for that particular line. That all works fine in testing, but I am wondering a few things....

How would this thing handle simultaneous access? Does it need flock, and if so, where do I stick it?

As is, if the uri is equal to a stored variable of URL in the flatfile (multi-line, multi-entry) it increases the count, if not the only way I could get it to work without wiping the flatfile was by adding an else statement that does a print DATA $line;.

Does that mean that each time the uri does not equal the $url that it is rewriting the entire file over again?

Basically, I am interested in how to make this a better application, and about the flocking whole thing...

A it seams that you're opening a file, closing it and re-opening it in an other mode. This invokes with some nasty problems under UNIX.

You'd better sysopen() the file with O_RDWR, and use flock() to lock the file, so it won't be edited by an other program at the same time. Check the Fcntl module for that. Maybe you don't understand this now, but read the some manuals about it.

Theoretically, your an other program can attempt to read or write to the same file, while you were working on it. Appently, you assume nothing has changed in the file when you re-open it (thus overwriting new added data), or when both programs are writing data to the file (simultaniously under UNIX), your file gets corrupt!!!!

This concept is handled in some perlfaq item. (perldoc -q increment). It's called: 'I still don't get locking. I just want to increment a number in a file'

About the rest of your program, maybe you can do something with grep() or map() but I don't know that exactly.