gpt4 book ai didi

perl - 逻辑运算符 : When do we use operator OR and when do we use ||

转载 作者:行者123 更新时间:2023-12-01 08:24:01 25 4
gpt4 key购买 nike

我正在使用 Perl 编写一个小脚本,但我很困惑必须使用哪个逻辑运算符来比较字符串

示例代码:

if (($app eq "appname1")OR($app eq "appname2")OR($app eq "appname3"))

我必须使用 OR (or) ||

最佳答案

一般的经验法则往往是:

  • 使用 ||组合 bool 运算,例如 if ($app eq "appname1" || $app eq "appname2" || $app eq "appname3") { ... }
  • 使用 or用于流量控制,例如 open my $fh, '<', $filename or die "Open failed: $!"
  • 如果您有疑问或您认为读者(包括六个月后的您自己)可能不清楚生成的结构,请使用括号

关于perl - 逻辑运算符 : When do we use operator OR and when do we use ||,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42153140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com