in reply to Re: Count of downloads from web site.
in thread Count of downloads from web site.

++ with reservations. You don't check to see if your match succeeded, and just let the script run into an invalid redirect or possibly the first of your dies. Giving the user an error page instead would be better. Also, when you reopen the counter file for writing, you lose the lock.
if(not defined $file) { print $some_error_page; exit; } sysopen FILE, "/path/to/logs/$file.txt", O_RDWR | O_CREAT or die "Can't open $file.txt: $!"; flock (FILE, LOCK_EX) or die("Can't lock $file.txt: $!"); my $count = <FILE> + 1; seek FILE, 0, 0; print FILE $count; truncate FILE, tell FILE; close FILE;
____________
Makeshifts last the longest.

Replies are listed 'Best First'.
Re^3: Count of downloads from web site.
by joshua (Pilgrim) on Jul 15, 2002 at 17:18 UTC
    You don't check to see if your match succeeded, and just let the script run into an invalid redirect or possibly the first of your dies.
    Ah, that's why I said...
    Obviously it wouldn't be great to use for production, but you get the idea.
    I didn't include an error routine just for simplicity sake, though it may have been a good idea to.
    Also, when you reopen the counter file for writing, you lose the lock.
    Thanks for the point there.

    Joshua