gpt4 book ai didi

perl - 哪些标识符被认为是动态的?

转载 作者:行者123 更新时间:2023-12-01 12:25:06 24 4
gpt4 key购买 nike

以下摘自perldoc perlmod :

The package statement declares the compilation unit as being in the given namespace. The scope of the package declaration is from the declaration itself through the end of the enclosing block, eval, or file, whichever comes first (the same scope as the my() and local() operators). Unqualified dynamic identifiers will be in this namespace, except for those few identifiers that if unqualified, default to the main package instead of the current one as described below.

上面“非限定动态标识符”短语中的术语“动态”似乎是指包中没有前缀my 的变量。也就是说,在下面的代码片段中,$v1 被视为动态标识符。是吗?

package Package_1;

$v1 = "v1_val";

my $v2 = "v2_val";

最佳答案

变量范围的两种一般类型是动态词法。基本上,词法变量的可见性是基于它们在源代码中的位置,而动态变量的可见性是在运行时确定的。

在 Perl 中,用 my 声明的变量是词法的,而任何其他变量都是动态的。这种区别变得直接相关的主要地方是 local 只能与动态(非my)变量一起使用,而不能与词法(my >) 变量。

另请参阅 Perl 常见问题解答,What's the difference between dynamic and lexical (static) scoping?

关于perl - 哪些标识符被认为是动态的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40579006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com