我如何比较在bash或Perl针对范围是多少? [英] How can I compare a number against a range in bash or Perl?
本文介绍了我如何比较在bash或Perl针对范围是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何脚本一些针对一系列的比较?
1是不是在2-5
块引用>或
3是在2-5
块引用>解决方案它甚至更好,在
Perl6
。连锁比较运算符:
如果(2'= $ X< = 5){
}智能匹配运算符:
如果($ X〜2..5){
}结:
如果($ X ~~任何2..5){
}鉴于/当操作员:
给予($ X){
当2..5 {
}
当6..10 {
}
默认{
}
}How to script a comparison of a number against a range?
1 is not within 2-5
or
3 is within 2-5
解决方案It's even better in
Perl6
.Chained comparison operators:
if( 2 <= $x <= 5 ){ }
Smart-match operator:
if( $x ~~ 2..5 ){ }
Junctions:
if( $x ~~ any 2..5 ){ }
Given / When operators:
given( $x ){ when 2..5 { } when 6..10 { } default{ } }
这篇关于我如何比较在bash或Perl针对范围是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文