括号代码部分使用严格/不严格?

Bracket code section in use strict / no strict?

我继承了一些当然不使用严格或警告的 perl 代码,我一直使用未初始化的变量等。

我想像这样将我正在修改的代码部分括起来:

use warnings;
use strict;

... my code changes and additions ...

no strict;
no warnings;

这似乎可行,但我在解读 the perldoc on use 的含义时遇到了问题,当它说这些是导入当前的编译器指令时 "block scope." 这是否意味着任何范围都可以具有use strict 未与 no strict 配对?全局范围尾部的 no strict 是否实质上取消了同一范围内较早的 use strict 的含义?

"block scope" 意味着 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
}