diff options
Diffstat (limited to 'Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE9.PL')
| -rw-r--r-- | Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE9.PL | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE9.PL b/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE9.PL new file mode 100644 index 0000000..0f83d36 --- /dev/null +++ b/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE9.PL @@ -0,0 +1,55 @@ +#!/Perl/bin/perl
+use strict;
+use warnings;
+# in Perl kann man mit qw "Quote Words" die Initialisierung vereinfachen
+$| = 1; #flush output
+
+my %words = qw (fred Kamel
+ barney Lama
+ betty Auster
+ wilma Auster);
+
+my ( $name, $guess, $secretword, $original_name );
+
+
+print "Wie heissen Sie? ";
+$name = <STDIN>;
+chomp $name;
+
+$original_name = $name;
+$name =~ s/\W.*//; # alles hinter dem ersten Wort vergessen
+$name =~ tr/A-Z/a-z/; # alles in Kleinbuschstaben
+
+if ( $name eq "gerhard" ) {
+ print "Hallo Gerhard, wie nett, dass du da bist!\n";
+}
+else {
+ print "Hallo $original_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;
+ }
+ print "Hallo $name, der Zugang ist erlaubt\n";
+}
+exit;
+
+
+
+
+
+
+
|
