開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語:Perl
その他参考書籍
1, 2.
コード(BBEdit)
sample.pl
#!/usr/bin/env perl use strict; use warnings; use utf8; use 5.016; binmode STDOUT, ':utf8'; binmode STDIN, ':utf8'; require "Oogaboogoo/date.pm"; my($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime; print "Today is ", Oogaboogoo::date::get_day($wday), ", ", Oogaboogoo::date::get_month($mon), " ", $mday, ", ", $year += 1900, "\n";
Oogaboogoo/date.pm
#!/usr/bin/env perl package Oogaboogoo::date; use strict; use warnings; use utf8; use 5.016; 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 $n = shift; die unless $n >= 0 and $n <= 6; $day[$n]; } sub get_month { my $n = shift; die unless $n >= 0 and $n <= 11; $month[$n]; } 1;
入出力結果(Terminal)
$ ./sample.pl Today is sen, pod 6, 2013 $
ちなみにJavaScriptの場合。
コード(BBEdit)
var Oogaboogoo = {}, td = new Date(), o; Oogaboogoo.date = function () { var day = ["ark", "dip", "wap", "sen", "pop", "sep", "kir"], month = ["diz", "pod", "bod", "rod", "sip", "wax", "lin", "sen", "kun", "fiz", "nap", "dep"]; this.getDay = function( n ) { if (! (typeof(n) === "number" && n >= 0 && n <= 6)) { throw { type: "曜日エラー", message: "有効な曜日ではありません" }; } return day[n]; }; this.getMonth = function ( n ) { if(!(typeof(n) === "number" && n >= 0 && n <= 11)) { throw { type: "月エラー", message: "有効な月ではありません" }; } return month[n]; }; }; o = new Oogaboogoo.date(); result = "Today is " + o.getDay(td.getDay()) + ", " + o.getMonth(td.getMonth()) + " " + td.getDate() + ", " + td.getFullYear(); $('#pre0').text(result);
pythonの場合。
sample.py
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- import datetime, Oogaboogoo.date td = datetime.date.today() day = td.weekday() + 1 if td.weekday() < 6 else 0 print("Today is {0}, {1} {2}, {3}".format( Oogaboogoo.date.getDay(day), Oogaboogoo.date.getMonth(td.month - 1), td.day, td.year))
sample.py
#!/usr/bin/env pythonb3.3 #-*- coding: utf-8 -*- day = ["ark", "dip", "wap", "sen", "pop", "sep", "kir"] month = ["diz", "pod", "bod", "rod", "sip", "wax", "lin", "sen", "kun", "fiz", "nap", "dep"] def getDay(n): if not (type(n) == type(10) and n >= 0 and n <= 6): raise Exception("有効な曜日ではない") return day[n] def getMonth(n): if not (type(10) == type(10) and n >= 0 and n <= 11): raise Exception("有効な月ではない") return month[n]
入出力結果(Terminal)
$ ./sample.py Today is sen, pod 6, 2013 $
0 コメント:
コメントを投稿