開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、6章(ハッシュ)の6.6(練習問題)1.を解いてみる。
その他参考書籍
6.6(練習問題)1.
コード(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 %names = (fred => 'flintstone',
barney => 'rubble',
wilma => 'flintstone');
while (1) {
print '名前を入力: ';
chomp( my $first_name = <STDIN>);
last unless $first_name;
if (exists($names{$first_name})) {
say "姓: $names{$first_name}";
} else {
say "データがありません";
}
}
入出力結果(Terminal)
$ ./sample.pl 名前を入力: fred 姓: flintstone 名前を入力: wilma 姓: flintstone 名前を入力: barney 姓: rubble 名前を入力: perl データがありません 名前を入力 $
0 コメント:
コメントを投稿