#!/usr/bin/env perl #=============================================================================== # # FILE: skript4-3.pl # # USAGE: ./skript4-3.pl # # DESCRIPTION: Erstellt eine Hash mit wörte die nach Buchstaben sorirt ist # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Martin Talarczyk (MT), martin@talarczyk.de # ORGANIZATION: Fachhochschule Südwestfalen, Iserlohn # VERSION: 1.0 # CREATED: 07.11.2015 11:33:21 # REVISION: --- #=============================================================================== use strict; use warnings; use utf8; use Data::Dumper; binmode (STDIN, ":encoding(UTF-8)"); binmode (STDOUT, ":encoding(UTF-8)"); binmode (STDERR, ":encoding(UTF-8)"); use open ":encoding(UTF-8)"; #=============================================================================== # Variabelen Deklarasion #=============================================================================== # Hash mit einem String als Key und einem feld als Wert. my %wordlist; my $wordkey; print "Skript startet...\n"; my $wordfp_file_name = 'GERMAN9.LST'; # input file name print "\n"; $wordkey = make_key("blablabla"); print "\n"; open my $wordfp, '<', $wordfp_file_name or die "$0 : failed to open input file '$wordfp_file_name' : $!\n"; while ( my $line = <$wordfp> ) { chomp $line; $wordkey = make_key($line); chomp $wordkey; push @{ $wordlist{ $wordkey } }, $line; } #print Dumper \%wordlist; #exit; close $wordfp or warn "$0 : failed to close input file '$wordfp_file_name' : $!\n"; print "Hash wurde erstellt...\n"; print "geben sie ein Word ein welches nur aus Bustabenbesteht\n"; my $inputKey = <>; chomp $inputKey; my $inputKeyuc = make_key($inputKey); chomp $inputKeyuc; while($inputKeyuc !~ /^[A-Z]{9}$/i) { print "Die eingabe war Falscht bitte erneut eingebe\n"; $inputKey = <>; chomp $inputKey; print $inputKey . "\n"; my $inputKeyuc = make_key($inputKey); print $inputKeyuc . "\n"; chomp $inputKeyuc; } if( exists $wordlist{ $inputKeyuc } ) { printf( "Eingabe: %s\nFolgende Woerter treffen zu:\n", $inputKey ); printf( "%s", "@{ $wordlist{ $inputKeyuc } }" ); } else { printf( "Dieses Wort existiert nicht.\n%s", $inputKey ); } #=== FUNCTION ================================================================ # NAME: make_key # PURPOSE: # PARAMETERS: Eine Sklar String der behandelt wird. # RETURNS: Feld mit string # DESCRIPTION: Ein Sortiren String. # THROWS: no exceptions # COMMENTS: none # SEE ALSO: n/a #=============================================================================== sub make_key { my ( $word ) = @_; defined $word or die "Es wurde keien String übergeben.\n"; my @temparry = split //, uc $word; @temparry = sort @temparry; my $erg = join "" , @temparry; return $erg; } ## --- end sub make_key