summaryrefslogtreecommitdiffstats
path: root/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE8.PL
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE8.PL
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE8.PL')
-rw-r--r--Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE8.PL50
1 files changed, 50 insertions, 0 deletions
diff --git a/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE8.PL b/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE8.PL
new file mode 100644
index 0000000..4e9e1bc
--- /dev/null
+++ b/Bachelor/Systemprogrammierung in Perl/examples/EXAMPLE8.PL
@@ -0,0 +1,50 @@
+#!/Perl/bin/perl
+use strict;
+use warnings;
+$| = 1; #flush output
+
+# in diesem Programm benutzen wir den Substitutionsoperator
+# s/muster/Ersetzung/
+# und den Transliteraloperator
+# tr/SUCHLISTE/ERSETZUNGSLISTE/
+
+my %words = ("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;
+ }
+}
+exit;
+