#!/usr/bin/env perl #=============================================================================== # # FILE: BuchstabenPipe.pl # # USAGE: ./BuchstabenPipe.pl # # DESCRIPTION: Wörter aus zwei datein vergleichen # # 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 09:27:56 # 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 $outputFile = "output.dat"; my $wolistfp_file_name = 'german.lst'; # input file name my %german; #Programm ausführen und auf stdin schreiben my $INPUTPIPE_command = './quadrat|'; # Eingabe Sortieren | ohene Doppelte | in schön > schreibe in my $OUTPUTPIPE_command = " | sort | uniq | column > $outputFile"; 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"; #==================================================================================== # 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 von quadrat aus über pipe, Schreibe in ausgabe datei, ersetzt quadrat.dat ar #==================================================================================== print "Auswertung...\n"; while (<$INPUTPIPE>) { # wenn Wort in $germen existirt Schreibe in Ausgabe datei print $OUTPUTPIPE $_ if exists $german {$_}; } close $OUTPUTPIPE or warn "$0 : failed to close pipe > $OUTPUTPIPE_command < : $!\n"; close $INPUTPIPE or warn "$0 : failed to close pipe > $INPUTPIPE_command < : $!\n"; print "Anzahl der Wörter: " . `wc -w $outputFile | cut -f1 -d' '`;