summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-11-06 00:57:56 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-11-06 00:57:56 +0100
commitc587f3c2bca6f4f770e6b9b14172dfc4f4d2ae68 (patch)
treeec030042d8144e12580626a0020256b5697e2d8e
parentae6ef1e1b29651ef9731a176d03774a52644bd8b (diff)
downloadSkriptsprachen-c587f3c2bca6f4f770e6b9b14172dfc4f4d2ae68.tar.gz
Skriptsprachen-c587f3c2bca6f4f770e6b9b14172dfc4f4d2ae68.zip
Add a3 s3 for piped riddle solver
-rw-r--r--Aufgabe3/skript3.pl74
1 files changed, 74 insertions, 0 deletions
diff --git a/Aufgabe3/skript3.pl b/Aufgabe3/skript3.pl
new file mode 100644
index 0000000..68ed536
--- /dev/null
+++ b/Aufgabe3/skript3.pl
@@ -0,0 +1,74 @@
+#!/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: 06.11.2015 00:27:04
+# 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 $ERGEBNIS_file_name = "loesung.dat";
+
+# pipe commands:
+my $INPUTPIPE_command = './quadrat|';
+my $OUTPUTPIPE_command = " | sort | uniq | column > $ERGEBNIS_file_name";
+
+open my $INPUTPIPE, $INPUTPIPE_command
+ or die "$0 : failed to open pipe > $INPUTPIPE_command < : $!\n";
+
+open my $OUTPUTPIPE, $OUTPUTPIPE_command
+ or die "$0 : failed to open pipe > $OUTPUTPIPE_command < : $!\n";
+
+my $german_file_name = 'german.lst'; # input file name
+
+open my $germanFile, '<', $german_file_name
+ or die "$0 : failed to open input file '$german_file_name' : $!\n";
+
+my %german;
+
+while (my $line = <$germanFile>)
+{
+ $german{uc $line} = 0;
+}
+
+close $germanFile
+ or warn "$0 : failed to close input file '$german_file_name' : $!\n";
+
+my @loesung;
+
+while (my $line = <$INPUTPIPE>)
+{
+ if (exists $german{uc $line})
+ {
+ push @loesung, uc $line;
+ }
+}
+
+print $OUTPUTPIPE @loesung;
+
+close $OUTPUTPIPE
+ or warn "$0 : failed to close pipe > $OUTPUTPIPE_command < : $!\n";
+close $INPUTPIPE
+ or warn "$0 : failed to close pipe > $INPUTPIPE_command < : $!\n";
+