我想从包含以下内容的文件中捕获行:" ExprControl"或" 5p3pAssays"或" Fusion"。
但是,我想跳过包含“Fusion”和“NoCall”的行。我如何正确省略这些行?下面的代码无法跳过包含" Fusion"和#34; NoCall"。谢谢。
...
open my $in_fh, '<', $full_tsv_file
or die qq{Unable to open "$full_tsv_file" for input: $!};
while ( <$in_fh> ) {
next if /^#/;
next if /\b(?:Fusion&NoCall)\b/;
next unless /\b(?:ExprControl|5p3pAssays|Fusion)\b/;
my @fields = split('\t');
my $location = $fields[$location_col]; $location =~ s/"//g;
...
答案 0 :(得分:2)
&
并不代表正则表达式中的“和”。与&&
匹配两次:
while (<>) {
next if /^#/ || /\bFusion\b/ && /\bNoCall\b/;
next unless /\b(?:Fusion|5p3pAssays|ExprControl)\b/;
print;
}
经过测试:
a ExprControl b
c 5p3pAssays d
e Fusion f NoCall g
h NoCall i Fusion j
k Fusion l