Skip to content

Instantly share code, notes, and snippets.

@satomixx
Created March 26, 2013 02:42
Show Gist options
  • Save satomixx/5242714 to your computer and use it in GitHub Desktop.
Save satomixx/5242714 to your computer and use it in GitHub Desktop.
スゲい簡単なPerl入門 -3rdDay ref: http://qiita.com/items/50ec171292de95e8ff3c
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};
}
$date->set_date(9);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment