Created
March 26, 2013 02:42
-
-
Save satomixx/5242714 to your computer and use it in GitHub Desktop.
スゲい簡単なPerl入門 -3rdDay ref: http://qiita.com/items/50ec171292de95e8ff3c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
my $date = main->new; | |
# Using Object(= Reference related with Package name) call subroutine in package | |
$date->set_date(9); | |
print "\n"; | |
sub new { | |
my $pkg = shift; | |
bless { | |
year => undef, | |
month => undef, | |
day => undef, | |
second => undef | |
},$pkg; | |
} | |
sub set_date { | |
# this $self is for receiving 1st argument(in this case, $date) | |
my $self = shift; | |
my $time_dereference = shift; | |
($self->{year},$self->{month},$self->{day},$self->{hour},$self->{minute},$self->{second}) = ( gmtime time + $time_dereference * 3600 )[5,4,3,2,1]; | |
$self->{year} += 1900; | |
$self->{month}++; | |
} | |
sub get_year { | |
my $self = shift; | |
return $self->{year}; | |
} | |
sub get_month { | |
my $self = shift; | |
return $self->{month}; | |
} | |
sub get_day { | |
my $self = shift; | |
return $self->{day}; | |
} | |
sub get_hour { | |
return $date->{hour}; | |
} | |
sub get_minute { | |
return $date->{minute}; | |
} | |
sub get_second { | |
return $date->{second}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$date->set_date(9); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment