summaryrefslogtreecommitdiffstats
path: root/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE7.PL
blob: 49c5a9b0898cfdf8d99a83702d61621c865f08f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/Perl/bin/perl
use strict;
use warnings;
$| = 1; #flush output

my %words  = ("fred", "Kamel", 
	   "barney", "Lama", 
	   "betty", "Auster", 
	   "wilma", "Auster" ); 
my ( $name, $guess, $secretword );

print "Wie heissen Sie? ";
$name = <STDIN>;
chomp $name;

# mit einem regul�ren Ausdruck wird die Abfrage flexibler
# ^=Zeilenanfang, \b=eine Wortgrenze, /i = ignoriere Gross und Kleinschreibung
# =~ Der Matching Operator
if ( $name =~ /^gerhard\b/i ) {
    print "Hallo Gerhard, wie nett, dass du da bist!\n";
} 
else {
    print "Hallo $name!\n"; # Standard Gru�
    if( exists $words{$name} ){
	$secretword = $words{$name} ; # Passwort holen
    }
    else  {
	$secretword = "groucho"; # f�r alle die kein Passwort haben
    }

    print "Wie lautet das Geheimwort? ";
    $guess = <STDIN>;
    chomp ( $guess );
 
    while ( $guess ne $secretword ) {
	print "Falsch geraten, nochmal. Wie lautet das Geheimwort? ";
	$guess = <STDIN>;
	chomp $guess;
    }
}
exit;