for循环附近的Perl语法错误?

时间:2013-12-20 14:44:29

标签: perl

在linux下运行它时,在下面给出的代码块...

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.

请建议。

1 个答案:

答案 0 :(得分: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