K
kazack
This is part of an elaborate web counter that I am in the process of
writing. I am hoping that once I am done with this little project I will be
able to move on to something else. I was told that this is a waste of time
and why am I trying to re-invent the wheel, but by re inventing the wheel
you learn alot. I have been modifying perl/cgi scripts for about a year and
now am in the process of actually trying to write one that works. I am not
familiar with what is good and bad habits when it comes to Perl/CGI so I am
hoping that someone can critique this and let me know how I can make this
code even better!!!
Thank you,
Shawn Mulligan
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
my ($date_num, $month) = (localtime $time)[3,4];
$month ++;
my $ipfile = sprintf '%02d%02d.vipd', ++$month, $date_num;
($slash, $document) = split(//, $ENV{'DOCUMENT_URI'});
if ($slash eq "/") { $ThisPage = $ENV{'DOCUMENT_URI'}; }
else { $ThisPage = "/$ENV{'DOCUMENT_URI'}"; }
if(-e $ipfile){
open(ip, "+<$ipfile") || die ("Can't open $ipfile\n");
}
else
{
open(ip, "+>>$ipfile") || die ("Can't open $ipfile\n");
}
while (<ip>) {
chop;
($ip, $file) = split(/::/, $_);
$ip{$file} = $ip;}
$ip{$ThisPage}++;
seek(ip, 0, 0);
foreach $file (keys %ip) { print ip $ip{$file}, "::", $file, "\n";
}
close(ip);
}
writing. I am hoping that once I am done with this little project I will be
able to move on to something else. I was told that this is a waste of time
and why am I trying to re-invent the wheel, but by re inventing the wheel
you learn alot. I have been modifying perl/cgi scripts for about a year and
now am in the process of actually trying to write one that works. I am not
familiar with what is good and bad habits when it comes to Perl/CGI so I am
hoping that someone can critique this and let me know how I can make this
code even better!!!
Thank you,
Shawn Mulligan
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
my ($date_num, $month) = (localtime $time)[3,4];
$month ++;
my $ipfile = sprintf '%02d%02d.vipd', ++$month, $date_num;
($slash, $document) = split(//, $ENV{'DOCUMENT_URI'});
if ($slash eq "/") { $ThisPage = $ENV{'DOCUMENT_URI'}; }
else { $ThisPage = "/$ENV{'DOCUMENT_URI'}"; }
if(-e $ipfile){
open(ip, "+<$ipfile") || die ("Can't open $ipfile\n");
}
else
{
open(ip, "+>>$ipfile") || die ("Can't open $ipfile\n");
}
while (<ip>) {
chop;
($ip, $file) = split(/::/, $_);
$ip{$file} = $ip;}
$ip{$ThisPage}++;
seek(ip, 0, 0);
foreach $file (keys %ip) { print ip $ip{$file}, "::", $file, "\n";
}
close(ip);
}