문제

I want to print a line of a file if it contains string A and it doesnt contain string B (also splitting into newlines at each colon). What is the proper syntax? Here is what I tried ( I want it print lines containing "bash" but to not print lines containing numbers):

my $file = passwdtest;
open(FH, "$file"); 
foreach (<FH>) { 
print join("\n", split(/:/, "$_")) if ($_ =~ /bash/ and $_ != /\d+/);
};

close FH;
도움이 되었습니까?

해결책

 $_ != /\d+/

is short for

 $_ != ($_ =~ /\d+/)

Instead of != you need !~

if ($_ =~ /bash/ and $_ !~ /\d+/);

다른 팁

Isn't that just:

if (/bash/ && ! /\d+/)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top