# file:
# range_operator.pl
# description:
# this file is the test file to show how to use the range operator in PERL
#
# conclusion:
# the state transition of the .. operator is as such
#
#
# (0, 0) false <---- 4 ------ (false) (1, 1)
# | ^
# | |
#(false -> true)1 Left .. right 3 (false -> true)
# | |
# V |
# (1, 0) (true) ----- 2 -----> true (0, 1)
#
#
# left is not evaluate in (true) state
# right is not evaluate in (false) state
#
# state flip happen on next round.
use strict;
my $line_no = 0;
print "start", "\n";
my $i = 100;
# the combination of (0, 1)
# and (1, 0) will evaluate as true
#
# while (0 .. 1) {
# print ++$i, "\n";
# sleep 1;
# }
open file, "< range_operator.pl";
# as you can see from the below output,
# the line 1 -- 6 return false on expression 1 . . /^$/
#
my $i = 0;
$i = 0;
my $line_end = 0;
line:
while (<file>) {
print ("\n") if !$line_end;
print "iteration -- cut point ", ++$i, " | ";
$line_end = 0;
next line if (1 .. /^$/);
$line_end = 1;
print "iteration", $i, "\n";
}
open file, "< range_operator.pl";
print "done", "\n";
The explaination:
1. while (0 .. 1) return true because (0, 1) on the state chart is true; so you will see a line printed every second.
2. The above output shall be as follow.
iteration -- cut point 1 |
...
iteration -- cut point 23 |
iteration -- cut point 24 | iteration24
...
as you can see,
22: # state flip happen on next round.
23:
24: use strict;
25:
though at line 23, the expression /^$/ shall evalute as true, according to the state map, the range operator shall be false, and according to the logic at line 23, it shall be the following output.
iteration -- cut point 23 | iteration23
But why?
It is because the state transition will happen the next round. So that explains why the output changes on line 24 rather than line 23;
Another thing to notice is that, after the line 24, the output does not change no matter what the text changes to... The reason is because:
- right is not evaluate in (false) state
- the left is a constant value (1)
分享到:
相关推荐
NOISE SUPPRESSION BASED ON TEAGER ENERGY OPERATOR
new操作符(new operator)和operator new的区别,会很有帮助
operator-sdk环境搭建 我的电脑环境为windows,安装operator-sdk需要自己编译构建二进制文件。 参考官方文档Compile and install from master 官方给的Prerequisites为: git mercurial version 3.9+ bazaar version...
Reminiscences of a Stock Operator by Edwin Lefevre, 75th anni. edition
chaosblade-operator镜像
inter-operator scenarios. Spectrum assignment decisions benefit from a distributed approach that can be realized by the pooling of resources at higher layers together. The paper investigates the ...
1.4 Arithmetic and Operator Overloading 6 1.5 More about Calling Methods 8 1.6 The apply Method 9 1.7 Scaladoc 10 Exercises 15 2 CONTROL STRUCTURES AND FUNCTIONS A1 17 2.1 Conditional Expressions 18 ...
aerospike-operator.tar
FiraCode + Operator Mono
k8s的operator, helloworld工程, 可以快速上手operator
新版启动calico所需镜像quay.io/tigera/operator:v1.20.3
The Algebra of Pseudo-Differential Operator on the Functional Space WrSmd (1985年)
Prometheus-operator在k8s上的实践操作
Tektronix 2465B Options and Operator Manual 泰克 400M 示波器2465B的操作使用手册 我个人自己制作的,花了几个小时弄的,希望能帮到大家。 首先该资源非常不好找,其次该资源在国外要钱买,自己想办法弄出图片...
cluster-operator.yml
operator=赋值自我检测,小程序,给自己参考学习
1.1 The Scala Interpreter — page 3 1.2 Declaring Values and Variables — page 5 1.3 Commonly Used Types — page 6 1.4 Arithmetic and Operator Overloading — page 7 1.5 Calling Functions and Methods ...
用于Apache Flink的Kubernetes Operator是用于在上运行的控制平面。 社区 提出问题,报告错误或提出功能或加入我们的频道。 查看 。 项目状态 贝塔 操作员正在积极开发中,对于Beta版本,不能保证API的向后兼容性...