Hello Jesse Smith,
Another point: Please note that it is both simpler and safer to avoid code duplication whenever possible:
my $db_name = $DATABASE2;
my $suffix = 'NO HTTP_REFERRER';
if (defined $ENV{'HTTP_REFERRER'} &&
length $ENV{'HTTP_REFERRER'} > 0)
{
$db_name = $database;
$suffix = "<A HREF=\"$ENV{'HTTP_REFERRER'}\">$ENV{'HTTP_REFERRER'}
+</a>";
}
$shortdate = `date +"%D %T %Z"`;
chomp $shortdate;
open(my $db, '>>', $db_name) or die "Cannot open database '$db_name' f
+or appending: $!";
print $db "$ENV{'REMOTE_ADDR'} - $shortdate - $ENV{'HTTP_USER_AGENT'}
+- " .
"<A HREF=\"http://$ENV{'HTTP_HOST'}$ENV{'REQUEST_URI'}\">htt
+p://$ENV{'HTTP_HOST'}$ENV{'REQUEST_URI'}</a> - $suffix\n";
close($db) or die "Cannot close database '$db_name': $!";
(Code untested, and with suggested improvements included: chomp instead of chop, the 3-argument form of open, a lexical filehandle, and testing for file open and close errors.)
Hope that helps,
|