sub new { my $type = shift; my $this = {}; $this->{'Bean'} = 'Colombian'; bless $this, $type; return $this; }
# # This subroutine sets the class name sub setBeanType{ my ($class, $name) = @_; $class->{'Bean'} = $name; print "Set bean to $name n"; } 1; 此类中,用$this变量设置一个匿名哈希表,将'Bean'类型设为'Colombian'。方法setBeanType()用于改变'Bean'类型,它使用$class引用获得对对象哈希表的访问。