perl嵌套,除非语句不等于使用\u0026\u0026的?
发布时间:2020-12-15 21:48:02 所属栏目:大数据 来源:网络整理
导读:7 foreach (@crons) { 8 unless (index($_,"cks") != -1) { 9 unless (index($_,"aab") != -1) { 10 unless (index($_,"lam") != -1) { 11 push (@found,$_); 12 } 13 } 14 } 15 } 为什么以上不能提供与以下相同的输出: 7 foreach (@crons) { 8 unless (ind
7 foreach (@crons) { 8 unless (index($_,"cks") != -1) { 9 unless (index($_,"aab") != -1) { 10 unless (index($_,"lam") != -1) { 11 push (@found,$_); 12 } 13 } 14 } 15 } 为什么以上不能提供与以下相同的输出: 7 foreach (@crons) { 8 unless (index($_,"cks") != -1 && index($_,"aab") != -1 && index($_,"lam") != -1) { 9 push (@found,$_); 10 } 11 } @crons有字符串列表,我试图得到所有没有“cks”,“aab”和“lam”的字符串 代码的第一部分做我想要的,但第二部分没有,在我看来,它应该…… 解决方法
让我们称你的条件为A,B,C.我们现在有了代码
unless (A) { unless (B) { unless (C) { 除非可能非常令人困惑,所以我们只使用if来编写它: if (!A) { if (!B) { if (!C) { 现在我们&&那些条件在一起: if (!A && !B && !C) { 这也可以写成 if (not(A || B || C)) { 这种等价称为de Morgan’s law (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |