为什么我没有收到 Perl 的警告?
考虑这两个用例:
sub test1 {
my $v = 1;
sub test2 { print $v }
# ...
}
第
for (0..3) {
my $foo = $_;
sub test1 { print $foo }
# ...
}
一个用例产生 Variable will not keep Shared
警告,而第二个则不会。看来这两种情况下变量都没有共享。为什么第二种情况没有任何警告?
Consider these two use cases:
sub test1 {
my $v = 1;
sub test2 { print $v }
# ...
}
and
for (0..3) {
my $foo = $_;
sub test1 { print $foo }
# ...
}
The first one produces a Variable will not stay shared
warning, while the second doesn't. It seems that the variable is not shared in both cases. Why isn't there any warning in the second case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来这可能是
warnings
pragma 中的错误或遗漏。更有趣的是,这种安排给出了不同的警告:
警告
Variable "$x" is not available
这些警告全部来自
pad_findlex()
API 调用,定义于 <代码>pad.c。这似乎与包含垫是否包含在简历中有关,但我不确定具体细节。
It seems that this may be a bug or omission in the
warnings
pragma.Adding to the fun, this arrangement gives a different warning:
Which warns
Variable "$x" is not available
These warnings all come from the
pad_findlex()
API call defined inpad.c
.It seems it has to do with if the containing pad is held within a CV or not, but I am not sure of the exact specifics.