■ハッシュ
・定義
%を先頭につける
%word = qw(
fred camel
barney gecko
betty alpaca
wilma alpaca
)
・参照
$word{ index }
#!/bin/perl %words = qw( fred camel barney gecko betty alpaca wilma alpaca ); print "What is your name? "; $name = <STDIN>; chomp ($name); if ($name eq "Erik") { print "Hello, Erick! How good of you to be here.\n"; } else { print "Hello, $name!\n"; $secretword = $words{$name}; # 合言葉を取得 if(($secretword = $words{$name}) eq "") { $secretword = ""; } print "What is the secret word? "; $guess = <STDIN>; chomp ($guess); while ($guess ne $secretword) { print "Wrong, try again. What is the secret word? "; $guess = <STDIN>; chomp ($guess); } } |