2013-12-20 36 views
1

,當我在linux下運行它下面給出的代碼塊...for循環附近的Perl語法錯誤?

my $source = 'BAD-IP-Addresses-LABEL'; 
my $type_description = 'honeypots-for-examnple'; 

open(FP, 'your-csv-file.csv') 
for my $line (<FP>) { 
    my ($hostname, $ip, $something1, $something2) = split(/,/, $line); 
    print OUT "$source $type_description $ip #FF0000 0 90 29\n"; 
} 
close(FP); 

它將引發我一個錯誤

syntax error at ./seculert_rest_qradar.pl line 131, near "$line (" 
syntax error at ./seculert_rest_qradar.pl line 135, near "}" 
Execution of ./seculert_rest_qradar.pl aborted due to compilation errors. 

我正在使用chmod 755腳本,爲全面瞭解劇本請去there.

請建議。

+7

這個問題似乎是題外話題,因爲它是關於丟失的分號 – geoffspear

+0

@Wooble我不知道這是一個關閉的實際類別。 –

+2

@HunterMcMillen:這是一個自定義的原因,因爲SO開發者偷走了我們的「過於本地化」,當他們說單字符錯別字應該被標記爲主持人注意他們說謊。 – geoffspear

回答

4

你是你OPEN語句後缺少一個分號:

my $source = 'BAD-IP-Addresses-LABEL'; 
my $type_description = 'honeypots-for-examnple'; 

open(FP, 'your-csv-file.csv') # <-- here 
for my $line (<FP>) { 
    my ($hostname, $ip, $something1, $something2) = split(/,/, $line); 
    print OUT "$source $type_description $ip #FF0000 0 90 29\n"; 
} 
close(FP); 

你沒有得到的語法錯誤,直到中途進入for循環,因爲這多少是完全有效的Perl:

open(FP, 'your-csv-file.csv') for my $line 
+0

理想情況下補充說明爲什麼(是語法錯誤。 – ysth

+0

我實際上並不完全確定我自己。謹慎解釋? –