我想創建一個腳本,從網站獲取日誌文件(內容),然後將其輸入到文本文件,但我有錯誤,如果使用嚴格存在:Perl獲取網頁內容,然後將其寫入文本文件
不能使用的字符串(「/ home/user中/下載/文」)爲標誌裁判而「嚴格裁判」在使用中./scriptname線92
而且通過移除使用嚴格的:我得到的另一個錯誤是:
文件名過長的./scriptname線91
我試過Perl: Read web text file and "open" it
但是,它沒有爲我工作。另外我是Perl的新手和Perl語法的混淆。
是否有任何建議或建議可用?
注意:該代碼確實存在與RoomOutProcessTT存在的整條線並將其顯示多次。
這是代碼。
my $FOutput = get "http://website/Logs/Log_number.ini";
my $FInput = "/home/User/Downloads/text";
open $FInput, '<', $FOutput or die "could not open $FInput: $!";
my $ctr;
my @results;
my @words = <$FInput>;
@results = grep /RoomOutProcessTT/, @words;
print "@results\n";
close $FInput;
open $FInput, '<', $FOutput or die "could not open $FInput: $!";
while(<$FInput>){
$ctr = grep /RoomOutProcessTT/, split ' ' , $_;
$ctr += $ctr;
}
print "RoomOutProcessTT Count: $ctr\n";
close $FInput;
「open」的第一個參數是文件句柄的名稱,而不是文件名本身。 '<'意味着打開指定的文件名後的文件名爲READ,並使用文件句柄名稱來引用它。你使用'open'是不正確的。見[參考](http://perldoc.perl.org/functions/open.html) –
你是說我應該爲filehandler創建另一個變量?我也這樣做了,但它會產生另一個錯誤,即「無法打開GLOB(0x17252b0):文件名太長,在./scriptname第92行。」我迷路了。 – galbert
這不是一個變量,它是一個裸號標識符,用於與您打開的文件交互,無論是閱讀還是書寫。以我的答案爲例。 –