我正在編寫一個腳本,查看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
當我按回車時,什麼也沒有發生。
不要編寫Perl 4風格的代碼。 '使用v5.10;嚴格使用;使用警告;'。 – Quentin 2013-02-13 17:35:09