在试图更好地理解无格变量以及它们与$sigiled变量的区别时,我发现,与$sigiled变量不同,sigilless变量在初始化后无法反弹:
my $a = 42;
my $b := $a;
$b := 42; # No exception generated
my \c := $a;
c := 42; # OUTPUT: «Cannot use bind operator with this left-hand side?»
Run Code Online (Sandbox Code Playgroud)
这是设计的吗?如果是这样,当$不禁止这些变量被禁止时,是否有目的或好处禁止无重复变量重新绑定?
Perl 6的具有实用的功能,允许人们得到任何波德声明符块附加到一个子程序(或类,角色等),使用该WHY方法:
#|(Some enlightening words about myfunc.)
sub myfunc (Int $i) { say "You provided an integer: $i"; };
#=(Some more words about myfunc.)
say &myfunc.WHY;
Run Code Online (Sandbox Code Playgroud)
这显示:
Some enlightening words about myfunc.
Some more words about myfunc.
Run Code Online (Sandbox Code Playgroud)
不幸的是,当一个子程序有多个候选者时,不能只调用.WHY子程序名:
#|(myfunc accepts an integer.)
multi myfunc (Int $i) { say "You provided an integer $i"; };
#|(myfunc accepts a string.)
multi myfunc (Str $s) { say "You provided a string $s"; };
say &myfunc.WHY;
Run Code Online (Sandbox Code Playgroud)
结果: …