Hello everyone. I have this code, originally courtesy of FireMyst, and I modified it. Originally it counted instances of user IP addresses from the records in log files. Now I want to get the addresses the users visited. I've got it pulling out the addresses and counting them, but I don't want the entire address. With the entire address it counts every different page visited on the same site. What I want is just everything from http:// up to the first backslash afterward. For example, if the address was I want it to be able to match the " portion so it can count that instead. That way it counts the occurrences of sites in lieu of individual pages on the sites. If I could match it that way, correct me if I'm wrong, but it would also print that way, right? Here's the code:
Any ideas folks?
Code:
my %IPs; #Added in this HASH
my $User;
my $Dd;
my $Tt;
my $Ap;
my $Dest;
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
#my $Choices;
#my $PickNumber;
print "Which file: ";
$TheDB = <STDIN>;
chomp($TheDB);
# Open the database file but quit if it doesn't exist
open(INDB, $TheDB) or die "The database $TheDB could " .
"not be found.\n";
while(<INDB>) {
$TheRec = $_;
chomp($TheRec);
($User, $Dd, $Tt, $Ap, $Dest) = split(/\s+/, $TheRec, 5);
$SuccessCount++;
if (exists $IPs{$Dest}) { #If the key exists, add 1
$IPs{$Dest}++;
}#End of if
else { #Otherwise, basically initialize the count to 1
$IPs{$Dest} = 1;
}#End of else
} # End of while(<INDB>)
if($SuccessCount == 0) { print "No records found.\n" }
else {
print "$SuccessCount records found.\n"
}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$RMonth = $mon + 1; #Adds one to month to obtain the correct month
$SYear = ($year % 100); #Runs modulo arithmetic on the year to get the correct short year
@DateMod = ($RMonth, $mday, $SYear, $hour, $min);
#Stores the value of Ops, converted into a readable format, into the variable $Stuff
$Filename = sprintf("%02d%02d%02d%02d%02d", @DateMod);
open(OUTDB, ">>d:\\hits\\countsite${Filename}.txt") or die "Can't do it.";
$key =~ s/http:\/\/*.*\///ig;
foreach $key(sort keys %IPs) #Print out each key
{print ("IP Address: " .$key. "\t\t\tNumber of instances: " . $IPs{$key} . "\n");
print OUTDB ("IP Address: " .$key. "\t\t\tNumber of instances: " . $IPs{$key} . "\n");}
print "Program finished.\n";
Any ideas folks?