我继承了一些当然不使用严格或警告的 perl 代码,并且我一直使用未初始化的变量等。
我想将我正在修改的代码部分括起来,如下所示:
use warnings;
use strict;
... my code changes and additions ...
no strict;
no warnings;
这似乎有效,但我在破译什么时遇到问题 the perldoc on use意味着当它说这些是导入当前“块范围”的编译器指令时。这是否意味着任何范围都可以有
use strict
未配对 no strict
?是no strict
在全局范围的尾部基本上取消了 use strict
的含义在同一范围内更早?
最佳答案
“块范围”意味着两者 use strict;
和 no strict;
从它们所在的位置到最里面的封闭块的末尾都有影响,所以不,稍后 no strict
不会撤消较早的 use strict
.它只是从代码中的那个点开始为最内部的范围更改它。所以:
{
use strict;
# strict in effect
{
# strict still in effect
no strict;
# strict not in effect
}
# strict in effect
no strict;
# strict not in effect
use strict;
# strict in effect
}
关于perl - 使用严格/不严格的括号代码部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28867039/