#!/usr/bin/perl use strict; use warnings; use 5.010; use POSIX; # create this outside the loop - it doesn't change # in fact it isn't used so why is it here at all? left in just in case my %dates = ( 'Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12', ); my $yesterday = strftime("%d/%b/%Y",localtime(time()-86400)); my $yesterdayHits=0; my $IPcount=0; my $totalhits=0; my $startDate; my $tm = scalar(localtime); my %ips=(); my @rows; # read from logfile(s) supplied on command line, instead of fixed file.... foreach my $line (<>) { $totalhits++; # (.+) is horrible as '.' includes spaces, this is better .... my $w = "(\S+?)"; $line =~ m/^$w $w $w \[$w:$w $w\] "$w $w $w" $w $w$/; # could do all these as one statement, but split for readability... my ($site, $logName, $fullName) = ($1,$2, $3); my ($date, $time, $gmt) = ($4, $5, $6); my ($req, $file, $proto) = ($7, $8, $9); my ($status, $length) = ($10, $11); $ips{$site}++; my ($day,$month,$year)=split"\/",$date; my $row = <$site$line EOF push @rows,$row; } # Real Men use Data::Dumper :-) foreach my $key ( sort keys %ips ) { print STDERR $key, " => ", $ips{$key}, "\n"; } # write to output file specified on command line instead... print < Access Counts

Today is: $tm

Yesterday was $yesterday

There are $IPcount unique visitors in the log

@rows

Start Date is $startDate

Total hits: $totalhits

Hits Yesterday: $yesterdayHits

IP LOGFILE

EOF