#!/usr/bin/perl
use CGI;
#if (length ($ENV{'QUERY_STRING'}) > 0){
#    $buffer = $ENV{'QUERY_STRING'};
#    @pairs = split(/&/, $buffer);
#    foreach $pair (@pairs){
#	($name, $value) = split(/=/, $pair);
#	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
#	$in{$name} = $value; 
#    }
#}

$q = new CGI;
$param = $q->param('param');

#$doc = @ARGV[0];
# the path for the log file
#$doc = $in{'doc'};
$logpath = '/home/html/admin/hblogs/'.$param.'.data';
 
# digits for the counter
#$pad = 5;

# opens the log file for reading, will be created if none exists.
open (LOG, "$logpath");
@file = <LOG>; # an array of the file contents
close(LOG);

$count = $file[0]; # the count value is the first line in the file, i.e. $file[0]
$count++; # increments the counter value

open (LOG, ">$logpath"); # opens the log file for writing
flock(LOG, 2); # file lock set
print LOG "$count\n"; # prints out the new counter value to the file
flock(LOG, 8); # file lock unset
close(LOG);

# sets the leading zeros padding for the counter
#$pad = "%.$pad"."d";

print "Content-type: text/html\n\n";


