这个问题可能很愚蠢。但我刚开始探索Perl。我正在使用Perl v5.16.2。我知道在5.10中已经引入了say
声明。为什么我应该在使用say函数时指定使用语句?
#!/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.
但是,当我加入的声明use 5.016;
,它给我正确的输出。
#!/usr/bin/perl
use 5.016;
say "Hello World!";
我的疑问是,我使用的是perl v5.16.2,它是5.010以上。为什么要在这里使用use
声明提到Perl版本?
我想指出的是,这在以前是语法错误,一些功能可能不需要'use'语句启用。 –
我认为你的意思是's/pattern/newpattern/r'和'$ var // 0'类型的东西?对,那是正确的。他们不打算向后兼容。你仍然可以通过'use'强制执行一个最低版本的perl版本(如果你正在做一些依赖于版本的版本,可能应该这样做) – Sobrique