加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – 为什么要在使用say函数时指定一个use语句?

发布时间:2020-12-15 21:22:55 所属栏目:大数据 来源:网络整理
导读:这个问题可能是愚蠢的.但是我刚开始探索Perl.我使用Perl v5.16.2.我知道在5.10中介绍了说明. #!/usr/bin/perlsay "Hello World!"; 当我尝试运行上面的程序,我得到以下错误: $./helloPerl String found where operator expected at ./helloPerl line 3,near
这个问题可能是愚蠢的.但是我刚开始探索Perl.我使用Perl v5.16.2.我知道在5.10中介绍了说明.
#!/usr/bin/perl

say "Hello World!";

当我尝试运行上面的程序,我得到以下错误:

$./helloPerl 
String found where operator expected at ./helloPerl line 3,near "say "Hello World!""
    (Do you need to predeclare say?)
syntax error at ./helloPerl line 3,near "say "Hello World!""
Execution of ./helloPerl aborted due to compilation errors.

但是当我添加语句使用5.016,它给我正确的输出.

#!/usr/bin/perl

use 5.016;
say "Hello World!";

我的怀疑是,我使用的是perl v5.16.2,它高于5.010.为什么要在这里使用use语句提及Perl版本?

解决方法

默认情况下不启用可能会中断兼容性的功能.

perldoc feature

It is usually impossible to add new syntax to Perl without breaking some existing programs. This pragma provides a way to minimize that risk. New syntactic constructs,or new semantic meanings to older constructs,can be enabled by use feature ‘foo’,and will be parsed only when the appropriate feature pragma is in scope. (Nevertheless,the CORE:: prefix provides access to all Perl keywords,regardless of this pragma.)

使用版本号,隐式启用所有功能,因为它也对perl版本应用约束.所以你不会因为说没有被执行而被绊倒了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读