我正试图使用我被指导要遵循的良好/适当/安全的Perl代码惯例来编写我的"Hello, World!"
程序:
use strict;
use warnings;
我已经使用(Strawberry) Perl 5.12 在我的主Windows 7操作系统上创建并成功运行了以下“Hello World”程序:
!#/usr/bin/perl
use strict;
use warnings;
print "Hello, World!\n";
正如预期收到的那样,我得到了"Hello, World!"
。
让我感到非常奇怪的是,在我的虚拟化Linux Mint 14操作系统上通过终端运行相同程序,使用Perl 5.14时,产生了以下错误:
"use" not allowed in expression at /PATH/hello_world.pl line 2, at end of line
syntax error at /PATH/hello_world.pl line 2, near "use strict"
BEGIN not safe after errors--compilation aborted at /PATH/hello_world.pl line 3.
后来我创作了其他的“Hello World”程序,没有使用use strict;
或use warnings;
这两行代码,还有一个版本是用了-w
参数,我在一些教程中看到过,它会打开警告提示功能(如果我没记错的话)。
我的另外两个版本都正常工作,它们都产生了我期望的结果:
Hello, World!
我不能确定的是,在Perl 5.14及更高版本中,是否需要在程序中使用use
语句,或者只需在第一行末尾写上-w
即可。
我希望在所有的Perl程序中都能使用统一的头部,无论它们是Windows还是Linux、Perl 5.12或5.14或其他版本。