Perl практика



              

Обработка различных вариантов ввода.


#!/usr/local/bin/perl %words = qw( #Perl 5.004 fred camel bamey llama betty alpaca irina alpaca ); print "What is you name? "; $name = <STDIN&gt ; chomp ($name); $original_name = $name; $name =~ s/\W.*//; $name =~ tr/A-Z/a-z/; if($name eq "german") { print "Hello, German! How good of you to be here!\n"; } else { print "Hello, $original_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); } }




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