如何确定当天是否在其他两天之间。
如果其他两天像Tues-Thursday那样,下面的代码可以运行
但是,如果我想让我的用户给出像星期一那样的范围,那该怎么办呢。
my $timestamp = time;
my $dow = ( localtime($timestamp) )[6];
my $range = '5-1'; # 5 being friday and 1 being monday
$range =~ m/(\d+)-(\d+)/;
my ( $start, $end ) = ( $1, $2 );
if ( $start >= 0 && $end <= 6 && $dow >= $start && $dow <= $end ) {
print "$dow falls between your range";
}
答案 0 :(得分:4)
my $in = ( $start <= $end
? $start <= $dow && $dow <= $end
: !( $end < $dow && $dow < $start )
);
或
my $in = ( $start <= $end
? $start <= $dow && $dow <= $end
: $dow <= $end || $start <= $dow
);