diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-11-20 00:48:41 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-11-20 00:48:41 +0100 |
| commit | eca42a1723472682dce2f0602b6294525b05bf50 (patch) | |
| tree | 5d6e6eda5c058286a99b8ecb3650475a5ca576e1 | |
| parent | 576aa6404fa9b4f7f2fd07f1e2ab317b30679014 (diff) | |
| download | Skriptsprachen-eca42a1723472682dce2f0602b6294525b05bf50.tar.gz Skriptsprachen-eca42a1723472682dce2f0602b6294525b05bf50.zip | |
Solve the game
| -rw-r--r-- | Aufgabe4/skript3.pl | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/Aufgabe4/skript3.pl b/Aufgabe4/skript3.pl new file mode 100644 index 0000000..73ecc70 --- /dev/null +++ b/Aufgabe4/skript3.pl @@ -0,0 +1,89 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: skript3.pl +# +# USAGE: ./skript3.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Stefan Suhren (su), suhren.stefan@fh-swf.de +# ORGANIZATION: FH Südwestfalen, Iserlohn +# VERSION: 1.0 +# CREATED: 20.11.2015 00:14:20 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use utf8; + +# enforce utf-8 mode +binmode (STDIN, ":encoding(UTF-8)"); +binmode (STDOUT, ":encoding(UTF-8)"); +binmode (STDERR, ":encoding(UTF-8)"); +use open ":encoding(UTF-8)"; + +my %wortliste; + +my $german9_file_name = 'GERMAN9.LST'; # input file name + +open my $german9, '<', $german9_file_name + or die "$0 : failed to open input file '$german9_file_name' : $!\n"; + +while (my $wort = <$german9>) +{ + chomp $wort; + my $key = make_key($wort); + push @{$wortliste{$key}}, $wort; +} + +close $german9 + or warn "$0 : failed to close input file '$german9_file_name' : $!\n"; + +print "Verwürfeltes Wort eingeben: "; +my $wort = <>; + +chomp $wort; +my $key = make_key($wort); + +if(exists $wortliste{$key}) +{ + print "Lösung(en) ist/sind: "; + foreach my $loesung (@{$wortliste{$key}}) + { + print $loesung . ", "; + } +} +else +{ + print "Wort konnte leider nicht gefunden werden."; +} + +#=== FUNCTION ================================================================ +# NAME: make_key +# PURPOSE: Creates a key for the hash of solutions. +# PARAMETERS: The string to make a key from. +# RETURNS: The key for the hash of solutions. +# DESCRIPTION: Creates a key for the hash of solutions. +# THROWS: no exceptions +# COMMENTS: none +# SEE ALSO: n/a +#=============================================================================== +sub make_key { + my ( $zeichenkette ) = @_; + + defined $zeichenkette or die "No zeichenkette supplied."; + + chomp $zeichenkette; + + my @feld = split //, uc $zeichenkette; + + @feld = sort @feld; + + return join ("", @feld); +} ## --- end sub make_key |
