
jr
Novice
Sep 25, 2001, 8:35 PM
Post #1 of 4
(392 views)
|
|
A better version
|
Can't Post
|
|
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... Any help would be apreciated, and here is the code so far:
#open and read data file open(DATA,"$datafile"); @lines = <DATA>; close(DATA); #start counting open(DATA,">$datafile"); foreach $line (@lines) { ($count, $section, $month, $year, $url, $title, $description) = split(/\|/,$line); if ($ENV{'DOCUMENT_URI'} eq $url) { $count++; print DATA ("$count|$section|$month|$year|$url|$title|$description"); } else { print DATA $line; } } Thanks in advance
|