perl – 为什么`a :: – > func?`有效?
发布时间:2020-12-15 21:18:33 所属栏目:大数据 来源:网络整理
导读:package a;sub func {print 1;}package main;a::-func; IMO只需要一个:: func,a-funk就可以了。 一个:: – FUNC;看起来很奇怪,为什么Perl支持这种奇怪的语法? 解决方法 引用色彩优雅的最新博客文章在 Modern Perl blog的主题:“避免裸词解析歧义”。 为
package a;
sub func {
print 1;
}
package main;
a::->func;
IMO只需要一个:: func,a-&funk就可以了。 一个:: – > FUNC;看起来很奇怪,为什么Perl支持这种奇怪的语法? 解决方法
引用色彩优雅的最新博客文章在
Modern Perl blog的主题:“避免裸词解析歧义”。
为了说明为什么这样的语法是有用的,这里是一个从您的示例演变的示例: package a;
our $fh;
use IO::File;
sub s {
return $fh = IO::File->new();
}
package a::s;
sub binmode {
print "BINMODEn";
}
package main;
a::s->binmode; # does that mean a::s()->binmode ?
# calling sub "s()" from package a;
# and then executing sub "open" of the returned object?
# In other words,equivalent to $obj = a::s(); $obj->binmode();
# Meaning,set the binmode on a newly created IO::File object?
a::s->binmode; # OR,does that mean "a::s"->binmode() ?
# calling sub "binmode()" from package a::s;
# Meaning,print "BINMODE"
a::s::->binmode; # Not ambiguous - we KNOW it's the latter option - print "BINMODE"
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
