# 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)
分享到:
相关推荐
Exporting the operator repeat_interleave to ONNX opset version 11 is not supported TypeError: 'torch._C.Value' object is not iterable (Occurred when translating repeat_interleave). 问题解决: 1....
(1 to 10).map(3 * _) // Applies a multiplication operation on each element of the range ``` - **Function with Default Arguments**: Functions can have default values for arguments, allowing them to ...
在C++编程中,`new`操作符和`operator new`是两个密切相关但不完全相同的概念,它们在内存管理和对象创建方面各自承担着特定的角色。 `new`操作符是C++语言内置的关键字,用于在堆上动态分配内存并创建对象。当执行...
"chaosblade-operator镜像" 是一个专门针对混沌工程实验的 Kubernetes 操作器,它用于在 Kubernetes 集群中安全、可控地引入故障,以评估和增强系统的容错能力。混沌工程是一种通过主动引入故障来验证系统稳定性的...
# An alternative way using the "dot operator": # Concatenate the DNA fragments into a third variable and print them $DNA3 = $DNA1 . $DNA2; print "Here is the concatenation of the first two fragments ...
在Kubernetes(简称k8s)生态系统中,Operator是一种高级的资源管理技术,它扩展了Kubernetes的能力,允许开发者定义和管理复杂的应用服务。"operator-helloworld.zip" 提供了一个入门级的Operator示例,帮助用户...
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
Prometheus Operator是一个工具,用于简化在Kubernetes平台上部署和管理Prometheus实例的操作。通过将Prometheus与其监控的目标关联起来,并在目标发生变化时自动更新配置,Prometheus Operator大大简化了Prometheus...
Cassandra-Operator是针对Apache Cassandra在Kubernetes集群中部署和管理的一个开源项目。它使得在Kubernetes环境中运行和扩展Cassandra数据库变得更加简单和自动化。在这个压缩包“cassandra-operator,apache-...
在大数据课程中,Scala编程基础是一个重要的组成部分,特别是在学习如何高效处理大规模数据时。本课程内容涵盖多个关键概念,如模式匹配、样例类、隐式函数和异常处理及泛型,这些都是Scala语言强大特性的体现。 ...
在C++编程中,"Operator Overloading" 是一个核心概念,它允许我们为已有的运算符赋予新的含义,使得它们可以用于自定义类型的操作。在标题"operator_C++_"中,"operator"显然指的是这个主题。描述提到的是“创建C++...
### 基于Teager能量算子的噪声抑制方法 #### 摘要与引言 本文介绍了一种基于Teager能量算子(TEO)的新型噪声抑制方法,旨在提高语音识别前端在噪声环境下的鲁棒性。该方法通过在Teager能量域内去除失真估计来实现...
标题中的“Operator Mono”和“Fira Code”都是广受欢迎的编程字体,它们在IT行业中尤其是程序员群体中非常流行。这两种字体设计独特,旨在提高代码的可读性和编写时的舒适度。 “Operator Mono”是由 Tyler Finck ...
aerospike-operator.tar
用于Kubernetes的Elasticsearch Operator可为Kubernetes服务以及Elasticsearch实例的部署和管理提供简单的监视定义。 安装后,Elasticsearch Operator将提供以下功能: 创建/销毁:使用运算符轻松为您的...