autogen.pl:自动生成这个帖子的perl代码 + 使用bless实现继承的例子 [code] #!/usr/bin/perl # 附件perl.tar.gz中,包含有如下文件: # autogen.pl、animal.pm、person.pm、testA.pl、testB.pl和test.pl # 运行autogen.pl即可以生成这个帖子的内容 @array = ( "autogen.pl:自动生成这个帖子的perl代码 + 使用bless实现继承的例子", "animal.pm:实现了animal类", "person.pm:实现了person类", "testA.pl:访问animal中定义的...
:roll: :roll: :roll: :roll: :roll: :roll: :roll: :roll: :roll: http://chinaunix.net/forum/viewtopic.php?t=136039
不太明白下面的这个bless到底有什么含义? 这样应该是$l成为了一个对象吧 [code] my $l = bless { $ddata ? ( $debg =>; "$dseq:DUP:$line" ) : (), }, __PACKAGE__; [/code] 上面的这个和下面的这个应该没有本质区别吧?除了上面的可以这样用$l->;以外 [code] my $l = $ddata ? ( $debg =>; "$dseq:DUP:$line" ) : (), [/code] 顺便问一下,__PACKAGE__是什么意思呢? 谢谢!
sub new { my ($class, $genes) = @_; my $self; if (ref $class) { $self = bless {} => ref $class; $self->{$_} = $class->{$_} for keys %$class; $self->{GENES} = $genes; $self->{CALCED} = 0; } else { # new mode. Genome is given goto &newSpecific; } return $self; } 还有一个 sub newRandom { my ($class, $length) = @_; my $self = bless { GENES ...
程序说明 网上的很多教程都没有把bless讲清楚,我通过摸索和实验,终于明白bless是什么意思了,简单的讲: bless有两个参数:对象的引用、类的名称。 类的名称是一个字符串,代表了类的类型信息,这是理解bless的关键。 所谓bless就是把 类型信息 赋予 实例变量。 程序包括5个文件: person.pm :实现了person类 dog.pm :实现了dog类 bless.pl : 正确的使用bless bless.wrong.pl : 错误的使用bless bless.cc : 使用C...