答案可能很明显,但我想知道是否有更短的写法:
if ($line =~ m/^REF: /){
$line =~ s/^REF: //;
# do something else
}
答案 0 :(得分:4)
s///
返回所做的替换次数。相当于你的代码:
if ($line =~ s/^REF: //) {
# do something else
}
答案 1 :(得分:1)
if ($line =~ s/^REF: //){
print $line."\n";
}
else {
print "Line not touched\n";
}