2013年1月14日月曜日

開発環境

『初めてのPerl 第6版』(Randal L. Schwartz, Tom Phoenix, brian d foy 共著、近藤 嘉雪 訳、オライリー・ジャパン、2012年、ISBN978-4-87311-567-2) の15章(プロセス管理)、15.6(練習問題)2を解いてみる。

その他参考書籍

2.

コード(BBEdit)

sample.pl

#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.016;
binmode STDOUT, ':utf8';
binmode STDIN, ':utf8';
use open ':encoding(UTF-8)';

my $date = `date`;
if($date =~ /(土|日)曜日/ || $date =~ /^S/){
  print "go play\n";
} else {
  print "get to work\n";
}

入出力結果(Terminal)

$ ./sample.pl
get to work
$ date
2013年 1月14日 月曜日 16時05分00秒 JST
$

ちなみにJavaScriptの場合。

コード(BBEdit)

var result;
var date = new Date();
if(/^S/.test(date) || /(土|日|)曜日/.test(date)){
  result = "go play";
} else {
  result = "get to work";
}
$('#pre0').text(result);



pythonの場合。

sample.py

コード(BBEdit)

#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

import os, re

child = os.popen('date')

date = child.read()
err = child.close()
if re.search(r"^S", date) or re.search(r"(土|日)曜日", date):
    print("go play")
else:
    print("get to work")

入出力結果(Terminal)

$ ./sample.py
get to work
$

0 コメント:

コメントを投稿