#!/usr/bin/perl use strict; use Fcntl qw (LOCK_EX); use Fcntl; use DB_File; use constant COUNT_FILE => "count.dbm"; my %count; my $num_hits; my $url = $ENV{REQUEST_URI}; local *DBM; print "Content-type : text/plain\n\n"; my $db = tie %count , "DB_File" , COUNT_FILE , O_RDWR | O_CREAT; if( $db ) { my $fd = $db->fd; open DBM , "+<&=$fd" or die "Count not dump DBM for lock: $!"; flock DBM,LOCK_EX; undef $db; $count{$url} = 0 unless exists $count{$url}; $num_hits = ++$count{$url}; untie %count; close DBM; print "$num_hits\n"; }else{ print "[Error processing counter data]\n"; }