開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語:Perl
その他参考書籍
1.
コード(BBEdit)
sample.pl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.016;
{
package MyDate;
use Carp;
my %methods = qw(day 3 month 4 year 5);
my @offset = qw(0 0 0 0 1 1900);
sub new {
my $class = shift;
bless {}, $class
}
sub DESTROY {}
sub AUTOLOAD {
our $AUTOLOAD;
(my $method = $AUTOLOAD) =~ s/.*:://s;
unless (exists $methods{$method}){
carp "メソッド名($AUTOLOAD)がわからない";
return;
}
my $i = $methods{$method};
(localtime)[$i] + $offset[$i];
}
}
my $date = MyDate->new;
print "day: " . $date->day . "\n";
$date->abcde;
print "month: " . $date->month . "\n";
print "year: " . $date->year . "\n";
入出力結果(Terminal)
$ ./sample.pl day: 11 Wide character in warn at /opt/local/lib/perl5/5.16.1/Carp.pm line 102. メソッド名(MyDate::abcde)がわからない at ./sample.pl line 33. month: 2 year: 2013 $
0 コメント:
コメントを投稿