--包(类)源码
#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;
---应用代码
--结果
时间: 2024-10-05 04:44:54