2014年4月17日木曜日

開発環境

初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、11章(Perlモジュール)の11.4(練習問題)2.を解いてみる。

その他参考書籍

11.4(練習問題)2.

コード(BBEdit, Emacs)

duration.pl

#!/usr/bin/env perl
# use diagnostics;
use strict;
use warnings;
use 5.016;
use utf8;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';

use DateTime;

my ($year, $month, $day) = @ARGV;
my $dt = DateTime->new( year => $year,
                        month => $month,
                        day => $day);
my $now = DateTime->now;

my $duration = $now - $dt;

printf "%d years, %d months, and %d days\n",
    $duration->in_units( qw/years months days/ );

入出力結果(Terminal)

$ ./duration.pl 1960 9 30
53 years, 6 months, and 17 days
$

0 コメント:

コメントを投稿