2012年5月1日火曜日

開発環境

『続・初めてのPerl 改訂版』(Randal L. Schwartz, brian d foy, Tom Phoenix 著、伊藤 直也田中 慎司吉川 英興 監訳、株式会社ロングテール/長尾 高弘 訳、オライリー・ジャパン、2006年、ISBN4-87311-305-9) の10章(大規模なプログラムの構築), 10.10(練習問題)を解いてみる。

1、2.

やり方の1つ。(「やり方は何通りもある」(TIMTOWTDI(There Is More Than One Way To Do It.)))

コード(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 number_to_day_name{
  my $num = shift @_;
  die unless 0 <= $num and $num <= 6;
  $day[$num];
}
sub number_to_month_name{
  my $num = shift @_;
  die unless 0 <= $num and $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;

$year += 1900;
$wday = Oogaboogoo::date::number_to_day_name($wday);
$mon = Oogaboogoo::date::number_to_month_name($mon);
print "Today is $wday, $mon $mday, $year\n";

入出力結果(Terminal)

$ ./sample.pl
Today is wap, sip 1, 2012
$

0 コメント:

コメントを投稿