我在Windows 7上运行ActiveState的32位ActivePerl 5.14.2.我想用Git预提交钩子来检测正在检查的语法错误的程序.(不知怎的,我只是设法做了这么糟糕的提交.)所以作为一个测试程序,我随机记下了这个:
use strict;
use warnings;
Syntax error!
exit 0;
Run Code Online (Sandbox Code Playgroud)
但是,它在没有警告的情况下编译和执行,退出时errorlevel为零.这个有效的语法怎么样?
我对Perl构造函数中发生的事情感到有点困惑.我发现这两个例子是perldoc perlbot.
package Foo;
#In Perl, the constructor is just a subroutine called new.
sub new {
#I don't get what this line does at all, but I always see it. Do I need it?
my $type = shift;
#I'm turning the array of inputs into a hash, called parameters.
my %params = @_;
#I'm making a new hash called $self to store my instance variables?
my $self = {};
#I'm adding two values to the instance variables …Run Code Online (Sandbox Code Playgroud) 标题几乎总结了,但无论如何这里是长版本.
在发布了一小段perl代码之后,我被告知要避免使用间接对象表示法,"因为它有几个副作用".评论引用了这一特定的行:
my $some_object = new Some::Module(FIELD => 'value');
Run Code Online (Sandbox Code Playgroud)
因为这就是我一直以来的做法,为了与时俱进,我因此问:
我正要问这位评论者,但对我而言,这是值得发表的.