Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果文件包含字符串 A 并且不包含字符串 B(也在每个冒号处拆分为换行符),我想打印一行文件。什么是正确的语法?这是我尝试过的(我希望它打印包含“bash”的行但不打印包含数字的行):
my $file = passwdtest; open(FH, "$file"); foreach (<FH>) { print join("\n", split(/:/, "$_")) if ($_ =~ /bash/ and $_ != /\d+/); }; close FH;
$_ != /\d+/
简称
$_ != ($_ =~ /\d+/)
而不是!=你需要!~
!=
!~
if ($_ =~ /bash/ and $_ !~ /\d+/);
不就是这样吗:
if (/bash/ && ! /\d+/)