--包(类)源码
#Date.pm
package Date;
sub new{
my $date={
the_year=>2015,
the_mon=>10,
the_day=>1,
};
bless($date);
return $date;
}
sub year{
my $self=shift;
$self->{the_year}=shift if(@_);
return $self->{the_year};
}
sub mon{
my $self=shift;
$self->{the_mon}=shift if(@_);
return $self->{the_mon};
}
sub day{
my $self=shift;
$self->{the_day}=shift if(@_);
return $self->{the_day};
}
sub setDate{
if(@_==4){
my $self=shift;
$self->mon($_[0]);
$self->day($_[1]);
$self->year($_[2]);
}
else{
print "Error happend\n";
}
}
sub disp{
my $self=shift;
print $self->mon."-".$self->day."-".$self->year."\n";
}
return 1;
---应用代码
--结果
本文转自 tiger506 51CTO博客,原文链接:http://blog.51cto.com/tiger506/1699708,如需转载请自行联系原作者