summaryrefslogtreecommitdiffstats
path: root/Aufgabe4
diff options
context:
space:
mode:
authorMartin Talarczyk <martin@talarczyk.de>2015-11-19 14:38:07 +0100
committerMartin Talarczyk <martin@talarczyk.de>2015-11-19 14:38:07 +0100
commitfa5fecb58e29d409039e2a522c2ae1cef3dbee37 (patch)
tree7ec7fe89d6bd9ee3588d9a2bb570216497939771 /Aufgabe4
parentf08f2d0e3798ff90b7e68c46751e15b7b991a2a0 (diff)
downloadSkriptsprachen-master.tar.gz
Skriptsprachen-master.zip
Stelle Aufgabe 4.2 fertig, verbessere Aufgabe 4.3HEADmaster
Diffstat (limited to 'Aufgabe4')
-rw-r--r--Aufgabe4/raetzelloesen.pl34
-rw-r--r--Aufgabe4/skript4-3.pl73
2 files changed, 77 insertions, 30 deletions
diff --git a/Aufgabe4/raetzelloesen.pl b/Aufgabe4/raetzelloesen.pl
index 8a4ec85..e7b0b07 100644
--- a/Aufgabe4/raetzelloesen.pl
+++ b/Aufgabe4/raetzelloesen.pl
@@ -79,24 +79,11 @@ $loesung = @word[ int rand @word];
@erb = verwuerfeln($loesung,$schwirichkeit);
-print_raetsel(@erb);
-
-$eingabe = <> ;
-
-
-while ( $eingabe ne $erb )
-{
- print "Sehr gut!\nwillst du noch mal Spielen\nyes or no"
- $eingabe = <>
-}
-
-
-sub print_raetsel {
- my ( @arry ) = @_;
-
my $count = 0;
-foreach my $char ( @arry ) {
+
+ print $loesung . "\n";
+foreach my $char ( @erb ) {
if ( ( $count % 3 ) eq 0 )
{
@@ -107,7 +94,16 @@ foreach my $char ( @arry ) {
$count++;
}
-} ## --- end sub print_raetsel
+$eingabe = <>;
+
+if($eingabe eq $loesung){
+ print "Das war richtig\n";
+}
+else {
+ print "Das war leider Flasch versuchen sie es erneut\n";
+ $eingabe = <>;
+}
+
#=== FUNCTION ================================================================
# NAME: verwuerfeln
@@ -149,11 +145,9 @@ sub verwuerfeln {
do {
$index1 = int rand $laenge;
$index2 = int rand $laenge;
- } while ( $index1 eq $index2 ); # ----- end do-while -----
+ } while ( $index1 == $index2 ); # ----- end do-while -----
@ergebnis[$index1,$index2] = @ergebnis[$index2,$index1];
}
return @ergebnis;
} ## --- end sub verwuerfeln
-
-
diff --git a/Aufgabe4/skript4-3.pl b/Aufgabe4/skript4-3.pl
index d914d66..2a599fa 100644
--- a/Aufgabe4/skript4-3.pl
+++ b/Aufgabe4/skript4-3.pl
@@ -21,7 +21,7 @@
use strict;
use warnings;
use utf8;
-
+use Data::Dumper;
binmode (STDIN, ":encoding(UTF-8)");
binmode (STDOUT, ":encoding(UTF-8)");
@@ -34,33 +34,82 @@ use open ":encoding(UTF-8)";
#===============================================================================
# Hash mit einem String als Key und einem feld als Wert.
my %wordlist;
-my $word;
+my $wordkey;
print "Skript startet...\n";
my $wordfp_file_name = 'GERMAN9.LST'; # input file name
+print "\n";
+$wordkey = make_key("blablabla");
+print "\n";
+
open my $wordfp, '<', $wordfp_file_name
or die "$0 : failed to open input file '$wordfp_file_name' : $!\n";
while ( my $line = <$wordfp> ) {
- #muss noch in String umgewandelt werden. make_key returent ein Arry.
- $word = make_key($line);
+ chomp $line;
- push @{ $wordList{ $wordKey } }, $line;
-}
+ $wordkey = make_key($line);
+
+ chomp $wordkey;
+
+ push @{ $wordlist{ $wordkey } }, $line;
+}
+#print Dumper \%wordlist;
+#exit;
close $wordfp
or warn "$0 : failed to close input file '$wordfp_file_name' : $!\n";
-print "\n";
+print "Hash wurde erstellt...\n";
+
+
+print "geben sie ein Word ein welches nur aus Bustabenbesteht\n";
+
+my $inputKey = <>;
+
+chomp $inputKey;
+
+my $inputKeyuc = make_key($inputKey);
+
+chomp $inputKeyuc;
+
+while($inputKeyuc !~ /^[A-Z]{9}$/i)
+{
+ print "Die eingabe war Falscht bitte erneut eingebe\n";
+
+ $inputKey = <>;
+
+ chomp $inputKey;
+
+ print $inputKey . "\n";
+
+ my $inputKeyuc = make_key($inputKey);
+
+ print $inputKeyuc . "\n";
+
+ chomp $inputKeyuc;
+}
+
+
+
+ if( exists $wordlist{ $inputKeyuc } )
+ {
+ printf( "Eingabe: %s\nFolgende Woerter treffen zu:\n", $inputKey );
+ printf( "%s", "@{ $wordlist{ $inputKeyuc } }" );
+ }
+ else
+ {
+ printf( "Dieses Wort existiert nicht.\n%s", $inputKey );
+ }
#=== FUNCTION ================================================================
# NAME: make_key
# PURPOSE:
# PARAMETERS: Eine Sklar String der behandelt wird.
# RETURNS: Feld mit string
-# DESCRIPTION: Teile ein String in Eine sortirtes groß geschiebenes Arry-
+# DESCRIPTION: Ein Sortiren String.
# THROWS: no exceptions
# COMMENTS: none
# SEE ALSO: n/a
@@ -68,10 +117,14 @@ print "\n";
sub make_key {
my ( $word ) = @_;
+ defined $word or die "Es wurde keien String übergeben.\n";
+
my @temparry = split //, uc $word;
- my @erg = sort @temparry;
+ @temparry = sort @temparry;
+
+ my $erg = join "" , @temparry;
- return @erg;
+ return $erg;
} ## --- end sub make_key