summaryrefslogtreecommitdiffstats
path: root/Aufgabe2/skript3.pl
blob: 367567d089b2758f1a3e6a0bf7498dc74a4676e9 (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
#!/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: 09.10.2015 10:31:56
#     REVISION: ---
#===============================================================================

use strict;
use warnings;
use utf8;
use English;

# enforce utf-8 mode
binmode (STDOUT, ":encoding(UTF-8)");
binmode (STDIN, ":encoding(UTF-8)");
use open ":encoding(UTF-8)";

# suppress line reading
undef $INPUT_RECORD_SEPARATOR;

my	$chapter_file_name = 'Stechlin-01.txt';		# input file name

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

printf "Zweck : Auszählung der Buchstabenhäufigkeiten\n\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";

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;