diff options
Diffstat (limited to 'Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE6.PL')
| -rw-r--r-- | Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE6.PL | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE6.PL b/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE6.PL new file mode 100644 index 0000000..6a00200 --- /dev/null +++ b/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE6.PL @@ -0,0 +1,39 @@ +#!/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;
+if ( $name eq "gerhard" ) {
+ print "Hallo Gerhard, wie nett dass du da bist!\n";
+}
+else {
+ print "Hallo $name!\n"; # Standard Gruß
+# mit exists kann man ueberpruefen ob ein Schluessel in einem Hash vorhanden
+# ist
+ 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;
+ }
+}
+
|
