- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以缩短这个场景:
use strict;
use warnings;
my $tests = [-1,0,1,2,];
foreach my $test (@$tests){
if ($test ne 0 and $test ne -1){ # THIS LINE
print "$test - Success\n";
}else{
print "$test - Error\n";
}
}
输出:
-1 - Error
0 - Error
1 - Success
2 - Success
进入类似的东西,你可以在比较语句中放置一组条件(我知道这段代码不起作用,是我正在搜索的类似语法的一个例子):
use strict;
use warnings;
my $tests = [-1,0,1,2,];
foreach my $test (@$tests){
if ($test ne (-1 or 0) ){ # THIS LINE
print "$test - Success\n";
}else{
print "$test - Error\n";
}
}
用例是这样的
foreach my $i (0..$variable){
test 1
if ($test->{a}->{$variable}->{b} ne 1 and $test->{a}->{$variable}->{b} ne 0){
...
}
# test 2
if ($test->{a}->{$variable}->{c} ne 3 and $test->{a}->{$variable}->{c} ne 4){
...
}
}
像这样的某些语法会大大简化此类测试的编写,而无需创建新变量以使代码易于阅读。
最佳答案
我会使用 List::Util::any
或 List::Util::all
:
if (any { $test != $_ } 0, 1) { ... }
if (all { $test != $_ } 0, 1) { ... }
类似于
if ($test != 0 || $test != 1) { ... }
if ($test != 0 && $test != 1) { ... }
请注意 List::Util
是一个核心模块,这意味着您无需安装任何东西即可运行。只需将 use List::Util qw(any all)
添加到您的脚本中即可。
关于perl - 是否可以在 perl 中的 'or' 或 'and' 比较中使用 'eq' 或 'ne' 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67125513/
我正在考虑通过慢速卫星连接创建数据查询 WCF 服务,我真的很喜欢 WCF 数据服务。我看到的问题是 HTTP 是一种非常冗长的格式,由于我所做的一切都是内部和 .NET,是否可以使用 NetTcpB
官方 MongoDB api 对 $ne 写的很少 http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24ne
当我尝试运行此查询时,我正在使用 mysql: Order.findAll({ where: { end_date: { $ne: null, }, }, });
我收藏的文档 rooms具有以下结构: { "_id": { "$oid": "4edaaa4a8d285b9311eb63ab" }, "users": [ {
我正在使用一开始具有以下结构的图表,但是我很难理解何时将其评估为true。 {{- if and .Values.vpceIngress.enabled .Values.http.paths (ne
我的 $ne : "" 无法与 pymongo 正常工作。 hashtable['ACR-WEB-01']=db.logs.find({"host_name" : "WEB-01"}, {"servi
我想获取一些文档,其中字段可能是$in某个数组(如果设置了过滤器,则进行条件查询)。 但是,我还需要无条件检查同一字段是否为 $ne: null。我知道 $in: [some value] 可用于防止
我正在尝试使用如下插入的数据运行以下查询。无论出于何种原因,值中为 0 的 $ne 似乎都不起作用。我使用 v2.0.4 在 linux 和 mac 上都试过了。还使用 mongo shell 运行了
我们有两个类,分别是“Parent”和“child”,如下所示: class Parent { parent_AddUser() { // add user code for
我一直在尝试创建一个奇特的 oh-my-zsh 主题,但不幸的是我遇到了一个恼人的障碍。 eval gray='$FG[245]' yellow='226' ret=$? # error check
我正在尝试排除某些行政区名称(例如布鲁克林、皇后区和史泰登岛)的查询,我只能排除一个,但不知道如何排除多个 只排除一个:db.rest.find({ borough : {$ne : "布鲁克林"}}
第一次在 Rails 项目上使用 Mongoid。 分机号是什么 .ne 以这样的作用域方法表示: scope :subscribed, -> { where( :unsubscri
数据: db.inventory.insertMany([ { _id: 1, item: null }, { _id: 2 }, { _id: 3, ite
db.test.find().pretty(); { "_id" : ObjectId("5537f2cfba0bf10870747d7e"), "a" : 1
我正在尝试查找 tipo=CD 和 canciones 不包含具有 title=Pajaritos 和 cancion=2 的子文档的所有文档> 这就是我想在 canciones 字段中实现的目标:
我一直在尝试执行以下 UNIX shell 脚本,但它不起作用。我通过 KornShell (ksh) 运行它。 echo $?; if [ $? -ne 0 ] then failed $LINE
所以我有如下所示的这一系列整数 from pandas import Series s = Series([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1
假设,我想将新项目保存/创建到 DynamoDb 表中,当且仅当不存在任何现有项目包含与我设置的值相同的 referenceId 时。 就我而言,如果表中没有任何其他 withReferenceId=
在 Android 应用程序中,我想根据以下格式的坐标设置地理点 50 27.858N,004 57.146E。我阅读了以下主题 how to convert coordinates to geoPo
我在 Express Node.js 服务器上运行了以下两个文件: 首页.js var express = require('express') var sequelize = require('se
我是一名优秀的程序员,十分优秀!