#!/usr/bin/perl
#
# Original code is from steve@vigra.com, particularly the flock commands.
#
# Heavily modified by Eric Klien
#
$LOCK_SH = 1;# Shared
$LOCK_EX = 2;# Exclusive
$LOCK_NB = 4;# Don't block when locking
$LOCK_UN = 8;# Unlock
$count_file=".count";
$source="/www/htdocs/mimejoramigo/index.html";
print "Content-type: text/html\n\n";
open (IN, "<$source") ||
die "Error retrieving homepage source file!";
if (!open (COUNT, "+< $count_file"))
{print "
No count file?
"; open (COUNT, "> $count_file");}
flock (COUNT, $LOCK_EX);
$count = ;
$count++;
seek (COUNT, 0, 0); # Rewind
print COUNT "$count\n"; # Overwrite
flock (COUNT, $LOCK_UN);
close (COUNT);
$count = &formatnum ($count,"d");
while ($string=) {$string =~ s/\#COUNT/$count/i;
print $string;}
# Format a number - precision, prefix and commas
# $var = &formatnum(number,format,prefix)
# &formatnum(12345,"d") - 12,345
# &formatnum(12345.678,".2f",$) - $12,345.68
sub formatnum {
local($_,$fmt,$prefix) = @_;
$_ = sprintf("$prefix%$fmt",$_);
@parts = split(/\./,$_);
1 while $parts[0] =~ s/(.*\d)(\d{3})/$1,$2/;
join(".",@parts);
}