#!/usr/bin/perl
#use a file named "count.txt" to keep the count of visitors.
$opened = open (FILE, "<", "count.txt");
#if file couldn't be opened, then we don't have visitors yet... if ( !$opened ) {
$visitors = 0;
}
else {
#read first line from file.. it contains the count
$visitors = <FILE>;
}
#number of visitors increases by 1 right? $visitors++;
#close before opening again (different mode) close (FILE);
#open same file to write the new data to it $opened = open (FILE, ">", "count.txt"); if (!$opened) {
die ("Error writing data to file...\n");
}
#write data to file
print FILE "$visitors";
#now write to the web server
print "Content-type:text/html\n\n";
print "<html><head><title>Visitor Count</title></head>";
print "<body><p>Total visitors till now: $visitors</p></body></html>";