这个问题可能是愚蠢的.但是我刚开始探索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.
#!/usr/bin/perl use 5.016; say "Hello World!";
我的怀疑是,我使用的是perl v5.16.2,它高于5.010.为什么要在这里使用use语句提及Perl版本?
解决方法
默认情况下不启用可能会中断兼容性的功能.
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版本应用约束.所以你不会因为说没有被执行而被绊倒了.