From fa5fecb58e29d409039e2a522c2ae1cef3dbee37 Mon Sep 17 00:00:00 2001 From: Martin Talarczyk Date: Thu, 19 Nov 2015 14:38:07 +0100 Subject: Stelle Aufgabe 4.2 fertig, verbessere Aufgabe 4.3 --- Aufgabe4/skript4-3.pl | 73 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 10 deletions(-) (limited to 'Aufgabe4/skript4-3.pl') 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 -- cgit v1.2.3-70-g09d2