開発環境
- 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) の10章(大規模なプログラムの構築)、10.10(練習問題)2を解いてみる。
2.
コード(TextWrangler)
oogaboogoo.pm
#!/usr/bin/env perl
package Oogaboogoo::date;
use strict;
use warnings;
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;
sample.pl
#!/usr/bin/env perl use strict; use warnings; require 'oogaboogoo.pm'; my($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime; $wday = Oogaboogoo::date::get_day($wday); $mon = Oogaboogoo::date::get_month($mon); $year += 1900; print "Today is $wday, $mon $mday, $year\n";
入出力結果(Terminal)
$ ./sample.pl Today is kir, lin 28, 2012 $
0 コメント:
コメントを投稿