在其他语言中我会写为什么“x = a或b”在Perl中不起作用?
testvar = onecondition OR anothercondition;
有,如果这两个条件中的testvar是真实的。但在Perl中,这不能按预期工作。
我想检查内容变量为空或与特定正则表达式匹配的情况。我有这个示例程序:
my $contents = "abcdefg\n";
my $criticalRegEx1 = qr/bcd/;
my $cond1 = ($contents eq "");
my $cond2 = ($contents =~ $criticalRegEx1);
my $res = $cond1 or $cond2;
if($res) {print "One or the other is true.\n";}
我本来希望$ res包含“1”,或者在用if()进行测试时证明是真的。但它包含空字符串。
我该如何在Perl中实现这个功能?周围表达
检查出[运算符优先级表(HTTP: //perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity)。用'||'比较'或'。 – user2864740 2014-09-01 10:02:42