PDA

View Full Version : a simple counter, giving me problems


Whiteknight
01-29-2004, 12:45 AM
Okay, I'm working on learning some perl, and I am trying to make a CGI counter for my website. I am trying to make it as simple as possible. I got the SSI working perfectly, but the counter always claims there is only 1 hit, the counter never increments. I'm new to perl, so some of the syntax (like the binds) are a little confusing. can anybody see an obvious problem I've made here?

#!/usr/bin/perl
print "Content-Type: text/HTML\n\n";
$page = "$ENV{'DOCUMENT_URI'}";
$data = "/var/www/html/data";
if ($page =~ /\/&/)
{
chop($page);
}
$page =~ s/[^\w]/_/g;
if (-e "$data$page")
{
open(FILE,">$data$page");
$count = <FILE>;
close(FILE);
}
else
{
$count = "0";
open(FILE,">$data$page");
print FILE $count";
close(FILE);
}
$count += 1;
print "$count";
open(FILE, ">$data$page");
print FILE "$count";
close(FILE);

imported_scavok
03-26-2004, 11:04 AM
Post is a bit old but if you or anyone else still needs it...


#!/usr/bin/perl
use CGI qw/:standard/;
print header();

$count = "/var/www/html/data/count.txt";

open (FILE, "$count");
@NUM = <FILE>;
close FILE;

foreach $f (@NUM){
$old = $f;
}

$new = $old+1;

open (FILE, ">$count");
print FILE $new;
close FILE;

Whiteknight
03-29-2004, 12:18 AM
yeah, since i made that post, I've become much more adept at perl. thanks for the post though.