我正在寫一個模式匹配的程序在perl中。但是出現錯誤..我已經看到關於此事的所有早期帖子,但是沒有找到解決方案...由於我是新來perl的所以我沒有得到什麼這個錯誤是一回事..
use of uninitialized value $line in string ne at line .. and in line ...
我在這裏附上一個Perl文件
use strict;
use warnings;
my $line = "";
open(OUTFILE, ">output.txt") or die ("cannot open file.\n");
if(open(file1,"match.txt") or die "Cannot open file.\n"){
$line = <file1>;
while ($line ne "") {
if (defined($line) && (line =~ m/\sregion\s/i)) {
print OUTFILE ("$line")};
$line = <file1>; # Problem Here
if (defined($line) && ($line =~ /\svth\s/)) {
print OUTFILE ("$line")
};
$line = <file1>; # Problem Here
}
}
我match.txt文件包含此類資料..
Some text here
region Saturati Saturati Linear Saturati Saturati
id -2.1741m -2.1741m -4.3482m 2.1741m 2.1741m
vth -353.9140m -353.9141m -379.2704m 419.8747m 419.8745m
Some text here
請解決問題....感謝
你可以在'open(...)或'...''周圍丟失'if(...)'。 –
在while循環後面有一個空字符「line」,並且您還應該使用open的3參數形式。此外,你應該使用file1文件句柄,而不是 – chilemagic
'grep「\ b(region | vth)\ b」match.txt' – TLP