in reply to counting yesterdays hits in a logfile
There are other and better ways using libraries such as Date::Calc to do the same thing.use POSIX qw(strftime); $time= localtime(time-(24*60*60)); $yesterday = strftime( '%d/%m/%y', $time);
`grep "$yesterday" logfile.log | wc -l`
Number of lines returned is the number of hits on your site. This command can be run inside a Perl script inside backticks.
However, the grep command exists in Perl too, so just read the file into an array and use the Perl grep command, as in scalar context it returns the number of matches.
open(LOGFILE,"<", "access.log")or die"Could not open log file."; my @logfile = <LOGFILE> my $hits = grep /$yesterday/, @logfile;
|
|---|