我正在编写一个脚本来查看 access_log 文件,以查看每个搜索引擎被访问了多少次,以及哪个搜索引擎被访问最多。我确信我的某些语法存在问题,但我什至无法判断,因为在运行它时我没有收到任何信息。任何帮助,将不胜感激!
代码:
#!/usr/bin/perl
use 5.010;
$googleCount = 0;
$msnCount = 0;
$yahooCount = 0;
$askCount = 0;
$bingCount = 0;
while (<STDIN>)
{
if (/(google.com)/)
{
$googleCount++;
}
if (/(msn.com)/)
{
$msnCount++;
}
if (/yahoo.com/)
{
$yahooCount++;
}
if (/ask.com/)
{
$askCount++;
}
if (/bing.com/)
{
$bingCount++;
}
}
print "Google.com was accessed $googleCount times in this log.\n";
print "MSN.com was accessed $msnCount times in this log.\n";
print "Yahoo.com was accessed $yahooCount times in this log.\n";
print "Ask.com was accessed $askCount times in this log.\n";
print "Bing.com was accessed $bingCount times in this log.\n";
我正在运行 MacOS。在我输入的终端中:
perl -w access_scan.pl access_log.1
当我按下回车键时,什么也没有发生。