Perl практика



              

Использование таблицы секретных слов - хеш.


#!/usr/local/bin/perl # did not use -w becouse "" %words = qw( #Perl 5.004 fred camel bamey llama betty alpaca irina alpaca ); print "What is you name? "; $name = <STDIN&gt ; chomp ($name); if($name eq "German") { print "Hello, German! How good of you to be here!\n"; } else { print "Hello, $name! \n"; $secretword = $words{$name}; if($secretword eq "") { $secretword = "grouhno"; } print "What is the secret word? "; $guess = <STDIN&gt ; chomp($guess); while($guess ne $secretword) { print "Wrong, try again. What is a secret word? "; $guess = <STDIN&gt ; chomp($guess); } }




Содержание  Назад  Вперед