物件導向編程 樣本 日期預設設定、更改、顯示

來源:互聯網
上載者:User

標籤:類

--包(類)源碼

#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;

---應用代碼

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/02/wKiom1YMM1LRzy2bAAB-kq8eJBE204.jpg" title="2015-10-01_030854.png" alt="wKiom1YMM1LRzy2bAAB-kq8eJBE204.jpg" />

--結果

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/73/FF/wKioL1YMM4mzdbvWAACSANGI6o8134.jpg" title="2015-10-01_030932.png" alt="wKioL1YMM4mzdbvWAACSANGI6o8134.jpg" />

本文出自 “奮鬥成就卓越” 部落格,請務必保留此出處http://tiger506.blog.51cto.com/318536/1699708

物件導向編程 樣本 日期預設設定、更改、顯示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.