在Perl 6中关闭变量声明

4
有没有办法让Perl 6不需要使用my来声明变量?我尝试了以下代码:
#!/usr/bin/perl6
no strict;
no warnings;

$z = "hello world";
say $z;

但是那并没有起作用。

===SORRY!=== Error while compiling ./helloworld.pl
Variable '$z' is not declared
at ./helloworld.pl:5
------> $z⏏ = "hello world";
    expecting any of:
        postfix

编辑:这是Rakudo中的一个漏洞。请参阅Perl 6规范:http://design.perl6.org/S01.html 。官方Rakudo包似乎很快就会过期。建议您从源代码编译:http://rakudo.org/how-to-get-rakudo/


1
在我的Rakudo中可以工作;你可能有一个更旧的版本。 - raiph
1
警告机制已经起作用,但是编译指示尚未实现。 - raiph
1
你为什么想要这样做? - Christopher Bottoms
1个回答

4

1
请注意,如果您收到不想看到的警告,可以使用 quietly;例如 my $a; $a = $a + 1 会出现警告:Use of uninitialized value of type Any in numeric context,但是 my $a; quietly $a = $a + 1 则不会。 - Elizabeth Mattijsen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接