Hi all,
I recently read chapter 11 about OOP from the online
book "learning perl". Here are some example codes
from chapeter 11:
sub new{
my $class =shift;
my [EMAIL PROTECTED];
bless ($self, $class);
return $self
}
sub name{ #version 1
my $self=shift;
my $set_name=shift;
$self->{_name}=$set_name if defined $set_name;
return $self->{_name}
}
Another version for the subroutine name
sub name{ #verstion 2
$_[0]->{_name}=$_[1] if defined }$_[1];
{$_[0]->{_name}
}
I feel a little bit confuse about the verion 2
subroutine name. The way it gets the value of
attribute name looks like this to me:
array element->{_name}
(I know that the $_[0] in the default array @_ is
actually an object $self. )
Any comments about the format used in version 2?
Thanks,
Li
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>