【发布时间】:2019-05-31 17:42:15
【问题描述】:
NEWBIE:所以今天我开始了一个学习 Perl 的教程,并且在我开始使用 #.###;
之前做得很好有人能解释一下省略版本时 Perl 的默认值是什么吗?
当我输入 use 5.30.0; 的值时,示例将运行。但是,如果我根本不指定行,我会根据 main 的位置和对 sayit() 的调用得到以下两个错误。
第一个错误如果包 main;打个招呼::sayit()... 在文件顶部。
无法在 helloWorld.pl 第 7 行通过包“hello::sayit”找到对象方法“say”(也许您忘记加载“hello::sayit”?)。
#!/usr/bin/perl
use strict;
#use warnings;
use warnings FATAL => 'all';
# default namespace is main
package main;
say hello::sayit();
say world::sayit();
# new namespace called hello
package hello;
sub sayit {
return "hello";
}
# new namespace called world
package world;
sub sayit {
return "world";
}
第二个错误如果包 main;打个招呼::sayit()... 在文件底部。
在 helloWorld.pl 第 20 行,“say hello::sayit”附近的操作员预期的位置找到了裸字
#!/usr/bin/perl
use strict;
#use warnings;
use warnings FATAL => 'all';
# new namespace called hello
package hello;
sub sayit {
return "hello";
}
# new namespace called world
package world;
sub sayit {
return "world";
}
# default namespace is main
package main;
say hello::sayit();
say world::sayit();
【问题讨论】:
-
你运行的是什么版本的 Perl?键入“perl --version”。 “use”命令应该只需要最低限度,并且可能还指定某个兼容性级别,例如当“say”被引入 Perl 时。默认兼容级别不能包含say。如果您不想包含“使用”行,请尝试“打印”而不是“说”。
-
试试
use feature qw(say)。请参阅perldoc feature 了解更多信息 -
我安装的是 5.30.0 版。