開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Perl
『続・初めてのPerl 改訂版』(Randal L. Schwartz, brian d foy, Tom Phoenix 著、伊藤 直也、田中 慎司、吉川 英興 監訳、株式会社ロングテール/長尾 高弘 訳、オライリー・ジャパン、2006年、ISBN4-87311-305-9) の15章(Exporter)、15.7(練習問題)2を解いてみる。
12
コード(TextWrangler)
sample.pl
#!/usr/bin/env perl use strict; use warnings; use Oogaboogoo::date qw(:all); my($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime; $wday = get_day($wday); $mon = get_month($mon); $year += 1900; print "Today is $wday, $mon $mday, $year\n";
date.pm
#!/usr/bin/env perl
use strict;
use warnings;
package Oogaboogoo::date;
use base qw(Exporter);
our @EXPORT = qw(get_day get_month);
our %EXPORT_TAGS = (
all => [@EXPORT],
);
my @day = qw(ark dip wap sen pop sep kir);
my @month = qw(diz pod bod rod sip wax lin sen kun fiz nap dep);
sub get_day{
my $num = shift @_;
die if $num < 0 && $num > 6;
$day[$num];
}
sub get_month{
my $num = shift @_;
die if $num < 0 && $num > 11;
$month[$num];
}
1;
入出力結果(Terminal)
$ ./sample.pl Today is ark, sen 5, 2012 $
0 コメント:
コメントを投稿