summaryrefslogtreecommitdiffstats
path: root/Aufgabe2/ZeichenZaeler.pl
diff options
context:
space:
mode:
Diffstat (limited to 'Aufgabe2/ZeichenZaeler.pl')
-rw-r--r--Aufgabe2/ZeichenZaeler.pl87
1 files changed, 87 insertions, 0 deletions
diff --git a/Aufgabe2/ZeichenZaeler.pl b/Aufgabe2/ZeichenZaeler.pl
new file mode 100644
index 0000000..e4aeaec
--- /dev/null
+++ b/Aufgabe2/ZeichenZaeler.pl
@@ -0,0 +1,87 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: ZeichenZaeler.pl
+#
+# USAGE: ./ZeichenZaeler.pl
+#
+# DESCRIPTION: Zählt die häufichkeit der Zeichen in einem Text.
+#
+# 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: 22.10.2015 09:26:40
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use utf8;
+use English;
+
+binmode (STDIN, ":encoding(UTF-8)");
+binmode (STDOUT, ":encoding(UTF-8)");
+binmode (STDERR, ":encoding(UTF-8)");
+use open ":encoding(UTF-8)";
+
+
+# suppress line reading
+my $old_INPUT_RECORD_SEPARATOR = $/;
+undef $INPUT_RECORD_SEPARATOR;
+
+my $chapter_file_name = 'Stechlin-01.txt'; # input file
+
+printf "Zweck : Auszählung der Buchstabenhäufigkeiten\n\n";
+
+#open file
+open my $chapter, '<', $chapter_file_name
+ or die "$0 : failed to open input file '$chapter_file_name' : $!\n";
+
+printf "Eingabedatei : %s\n\n", $chapter_file_name;
+
+printf "Tabelle der Zeichenhäufigkeiten :\n\n";
+
+my $kapitel = <$chapter>;
+
+my %haeufig;
+my $zelen = 0;
+
+while (my $char = chop $kapitel)
+{
+ if ($char eq "\n")
+ {
+ $zelen++;
+
+ next;
+ }
+ $haeufig{$char}++;
+}
+
+close $chapter
+ or warn "$0 : failed to close input file '$chapter_file_name' : $!\n";
+#close file
+
+
+my $count = 0;
+my $countChars = 0;
+
+foreach my $char (sort keys %haeufig)
+{
+ $count++;
+ $countChars += $haeufig{$char};
+ printf "%5s = %5d", $char, $haeufig{$char};
+ if($count % 3 == 0)
+ {
+ printf "\n";
+ }
+}
+
+printf "\n\n%5d Zeichen\n", $countChars;
+printf "%5d Zeilenvorschübe\n", $zelen;
+printf "%5d Zeichen insges.", $countChars + $zelen;
+