Created
January 10, 2010 11:59
-
-
Save yusukebe/273456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; # おまじない | |
use warnings; | |
use Encode; | |
use utf8; | |
# スカラー | |
my $title = "true tears で学ぶ Perl 入門"; | |
# リスト | |
my @names = qw(Shinichirou Noe Hiromi Aiko Nobuse); | |
# 標準出力 | |
print "Dareni suru?\n"; | |
# 関数 | |
print join( ', ', @names ) . "\n"; | |
# 標準入力 | |
my $name = <STDIN>; | |
# 関数 | |
chomp($name); | |
# エラー処理 | |
die "眞一郎の靴の底にもあぶらむし♪\n" unless $name; | |
# 制御構文, grep, 正規表現 | |
if ( grep { $_ =~ /$name/i } @names ) { | |
# Encodeモジュール, サブルーチンの使用 | |
print "$name: " . encode( 'utf8', talk($name) ) . "\n"; | |
} | |
else { | |
print "Chanto erande yo!\n"; | |
} | |
# サブルーチン定義 | |
sub talk { | |
my $name = shift; | |
# リファレンス | |
my $map = { | |
Shinichirou => [ '全部ちゃんとするから', '君の涙を' ], | |
Noe => [ | |
'私 涙、あげちゃったから', | |
'はい、ぱちぱちってして', | |
'ちゃんと言って、ここに書いて', | |
'なかなか飛べないね' | |
], | |
Hiromi => [ | |
'私 何がしたいの', | |
'おせっかいな男の子ってバカみたい', | |
'雪が降っていない街', | |
'何も見てない私の瞳から', | |
'あなたが好きなのは私じゃない', | |
], | |
Aiko => [ | |
'どうなった? こないだの話', | |
'それ なんの冗談?' | |
], | |
Nobuse => ['よー'], | |
}; | |
# デリファレンス | |
my @sentences = @{ $map->{$name} }; | |
# リスト要素の抽出 | |
return $sentences[ rand @sentences ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment