開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、2章(スカラーデータ)の2.12(練習問題)3を解いてみる。
その他参考書籍
3.
コード(BBEdit, Emacs)
sample.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';
my $pi = 3.14159264;
print '円の半径を入力: ';
chomp(my $r = <STDIN>);
my $c;
if ($r >= 0) {
$c = 2 * $r * $pi;
} else {
$c = 0;
}
print "半径${r}の円の円周の長さは約${c}。\n";
入出力結果(Terminal)
$ ./sample.pl 円の半径を入力: 12.5 半径12.5の円の円周の長さは約78.539816。 $ ./sample.pl 円の半径を入力: -1 半径-1の円の円周の長さは約0。 $
0 コメント:
コメントを投稿