【发布时间】:2015-03-18 02:26:56
【问题描述】:
我有一个文件 place.txt,内容如下:
I want to go Rome. Will Go.
I want to go Rome. Will Not Go.
I want to go Rome. Will Not Go.
I want to go Rome. Will Go.
I want to go India. Will Not Go.
I want to go India. Will Not Go.
I want to go Rome. Will Go.
我想读取这个文件,并将行与“我想去罗马”模式匹配。并在 perl 中省略与此文件中的模式匹配的那些行。
我的示例代码是:
$file = new IO::File;
$file->open("<jobs.txt") or die "Cannot open jobs.txt";
while(my $line = $file->getline){
next if $line =~ m{/I want to go Rome/};
print $line;
}
close $file;
注意:我的文件会很大。我们可以使用 sed 或 awk 吗?
【问题讨论】:
-
问题可能是双括号。使用
m{...}或m/.../或/.../,但不要使用m{/.../}。它尝试查找包含“/”的模式。