diff options
Diffstat (limited to 'Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE7.PL')
| -rw-r--r-- | Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE7.PL | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE7.PL b/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE7.PL new file mode 100644 index 0000000..49c5a9b --- /dev/null +++ b/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE7.PL @@ -0,0 +1,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;
|
