Perl是否可以组合2个if语句?

时间:2013-12-06 02:01:53

标签: perl

所以现在这就是我所拥有的:

if ($stuff =~ /^(bad|alsobad)$/) {
print "Seems incorrect";
exit 0;
}

在某种程度上可能有类似的东西吗?

    if ($stuff =~ /^(bad|alsobad)$/){
#
    if ($twostuff =~ /^(nan|na)$/) {
    print "Seems incorrect";
    exit 0;
    }
#
    }

1 个答案:

答案 0 :(得分:3)

您的代码:

if ($stuff =~ /^(bad|alsobad)$/){
    if ($twostuff =~ /^(nan|na)$/) {
        print "Seems incorrect";
        exit 0;
    }
}

......应该工作得很好。另一种选择是:

if ( $stuff =~ /^(bad|alsobad)$/ and $twostuff =~ /^(nan|na)$/ ){
    print "Seems incorrect";
    exit 0;
}