Monday, April 21, 2008

Simple PERL counter

A simple PERL counter that counts the number of times a page is loaded. The script reads the number stored in "counter.txt" and increments it by one and displays the same. The incremented value is then stored in "counter.txt".

#!/usr/bin/perl
print "Content-type:text/html\n\n";

open (MYFILE, 'counter.txt');
chomp($count=);
close (MYFILE);

$count++;

print $count;

open (MYFILE, '>counter.txt');
print MYFILE "$count\n";

close (MYFILE);

A simple script to demonstrate reading from and writing to a file using PERL.

No comments: