相关疑难解决方法(0)

面向对象的Perl构造函数语法和命名参数

我对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)

oop perl constructor instance-variables

27
推荐指数
6
解决办法
2万
查看次数

标签 统计

constructor ×1

instance-variables ×1

oop ×1

perl ×1