summaryrefslogtreecommitdiffstats
path: root/Aufgabe3/Buchstabenraetzel.pl
blob: cb882b47e0089a1c5ca0fd8932e02bbb8a7c6846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env perl 
#===============================================================================
#
#         FILE: Buchstabenrätzel.pl
#
#        USAGE: ./Buchstabenrätzel.pl  
#
#  DESCRIPTION: Testet zwei Wort listen auf gleiche vorkommen. 
#
#      OPTIONS: ---
# REQUIREMENTS: ---
#         BUGS: ---
#        NOTES: ---
#       AUTHOR: Martin Talarczyk (MT), talarczyk.martin@fh-swf.de
# ORGANIZATION: FH Südwestfalen, Iserlohn
# Matrikel-Nr.: 10036162
#      VERSION: 1.0
#      CREATED: 28.10.2015 08:43:14
#     REVISION: ---
#===============================================================================

use strict;
use warnings;
use utf8;

binmode (STDIN, ":encoding(UTF-8)");
binmode (STDOUT, ":encoding(UTF-8)");
binmode (STDERR, ":encoding(UTF-8)");
use open ":encoding(UTF-8)";


#-------------------------------------------------------------------------------
#  Variabelen Deklarasion
#-------------------------------------------------------------------------------

my	$wolistfp_file_name = 'german.lst';		# input file name
my	$infifp_file_name = 'quadrat.dat';		# input file name
my $outputFile = "loesung.dat";
#hash mit Deutschen Wörtern aus german.list
my %german;
my @loesung;
my @loesung_unique;


#====================================================================================
# Wörter list lesen german.lst
#====================================================================================
print "Wörter liste lesen...\n";

open  my $wolistfp, '<', $wolistfp_file_name
	or die  "$0 : failed to open  input file '$wolistfp_file_name' : $!\n";



while (my $word = <$wolistfp>)
{
	$word = uc $word;

	$german {$word} = $word;
}

close  $wolistfp
	or warn "$0 : failed to close input file '$wolistfp_file_name' : $!\n";

#====================================================================================
# lese quadrat.dat 
#====================================================================================
print "Lese Input Datei...\n";

open  my $infifp, '<', $infifp_file_name
	or die  "$0 : failed to open  input file '$infifp_file_name' : $!\n";

while ( my $line = <$infifp>)
{
	#Wenn ein Deutsches Wort (german.list) füge zu lösung hinzu. 
	push (@loesung, $line) if exists $german {$line};
}

close  $infifp
	or warn "$0 : failed to close input file '$infifp_file_name' : $!\n";

print "Feld Sortiren...\n";
@loesung = sort @loesung;


print @loesung . " Wörter gefunden!\n";

#====================================================================================
# Entferne dopelte 
#====================================================================================
print "entferen dopelte...\n";

my $count = 0;
push @loesung_unique, $loesung[$count];

foreach ( @loesung)
{
	if ($loesung_unique[-1] ne $_)
	{
		push @loesung_unique, $_;
	}
}

#====================================================================================
# Schrebie in Ausgabedatei loesung.dat
#====================================================================================

print "Schreibe in Ausgabedatei\n";


my	$opfp_file_name = 'loesung.dat';		# output file name

open  my $opfp, '>', $opfp_file_name
	or die  "$0 : failed to open  output file '$opfp_file_name' : $!\n";

print $opfp @loesung_unique;

close  $opfp
	or warn "$0 : failed to close output file '$opfp_file_name' : $!\n";

print @loesung_unique . " Wörter ohne doppelte gefunden!\n";