diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-10-12 10:46:07 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-10-12 10:46:07 +0200 |
| commit | 3ae857f9352bf05d052db0301b0a718399ff85a6 (patch) | |
| tree | e295b9fa6e43fb3b0623778a0495c5a650991577 | |
| parent | 078e927e51cbfa18e26bd35076a0eb5b5bf1ffb8 (diff) | |
| download | Skriptsprachen-3ae857f9352bf05d052db0301b0a718399ff85a6.tar.gz Skriptsprachen-3ae857f9352bf05d052db0301b0a718399ff85a6.zip | |
Add assignment no.2
| -rw-r--r-- | Aufgabe2/skript1.pl | 53 | ||||
| -rw-r--r-- | Aufgabe2/skript2.pl | 46 | ||||
| -rw-r--r-- | Aufgabe2/skript3.pl | 74 |
3 files changed, 173 insertions, 0 deletions
diff --git a/Aufgabe2/skript1.pl b/Aufgabe2/skript1.pl new file mode 100644 index 0000000..971f6dd --- /dev/null +++ b/Aufgabe2/skript1.pl @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: skript1.pl +# +# USAGE: ./skript1.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:06:46 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use utf8; + +# enforce utf-8 mode +binmode (STDOUT, ":encoding(UTF-8)"); +binmode (STDIN, ":encoding(UTF-8)"); +use open ":encoding(UTF-8)"; + +my $poem_file_name = 'Rilke-Herbsttag.txt'; # input file name + +open my $poem, '<', $poem_file_name + or die "$0 : failed to open input file '$poem_file_name' : $!\n"; + +my @poemRead; +my $lines = 0; + +while (my $line = <$poem>) +{ + push(@poemRead, $line); + print $line; + ++$lines; +} + +close $poem + or warn "$0 : failed to close input file '$poem_file_name' : $!\n"; + +printf "Read lines: $lines\n"; + +print reverse @poemRead; + +print sort @poemRead; + diff --git a/Aufgabe2/skript2.pl b/Aufgabe2/skript2.pl new file mode 100644 index 0000000..a269c5d --- /dev/null +++ b/Aufgabe2/skript2.pl @@ -0,0 +1,46 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: skript2.pl +# +# USAGE: ./skript2.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:06:46 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use utf8; + +# enforce utf-8 mode +binmode (STDOUT, ":encoding(UTF-8)"); +binmode (STDIN, ":encoding(UTF-8)"); +use open ":encoding(UTF-8)"; + +my $poem_file_name = 'Rilke-Herbsttag.txt'; # input file name + +open my $poem, '<', $poem_file_name + or die "$0 : failed to open input file '$poem_file_name' : $!\n"; + +my $poemRead; + +while (my $line = <$poem>) +{ + $poemRead = $poemRead . $line; +} + +close $poem + or warn "$0 : failed to close input file '$poem_file_name' : $!\n"; + +print sort $poemRead; + diff --git a/Aufgabe2/skript3.pl b/Aufgabe2/skript3.pl new file mode 100644 index 0000000..bf501aa --- /dev/null +++ b/Aufgabe2/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: 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"; + +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; |
