Thread Vokale im Umlaute wandeln (20 answers)
Opened by Tom950 at 2014-03-18 06:48

FIFO
 2014-03-19 09:49
#174290 #174290
User since
2005-06-01
469 Artikel
BenutzerIn

user image
Hi, hier mal ein Beispiel, wie Du alle Wörter ( [A-Za-z0-9_] ) in einem Skalar verarbeiten kannst, in diesem Fall werden alle .txt-Files jeweils am Stück (nicht zeilenweise) eingelesen und eine Wortliste aller Umlautworte erstellt, alles noch simpel gestrickt fürs Prinzip. Aus dieser Wortliste kannst Du dann mit Deinen Ausnahmen Such-/Ersetz-Muster bauen und in einem zweiten Schritt alle Ersetzungen durchführen.
Code (perl): (dl )
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
use warnings;
use strict;

my %umlautWords;
my $umlautWordPattern = qr( [aou]e )ixo;

for my $file ( glob( 'C:/myPath/*.txt' ) ) {
    my $data;
    open( my $FH, '<', $file ) or next;
    {
        local $/;
        $data = <$FH>;
    }
    close $FH;
    
    while ( $data =~ / \b (\w+) \b /oxg ) {
        my $word = $1;
        if ( $word =~ $umlautWordPattern ) {
            next if exists $umlautWords{ $word };
            $umlautWords{ $word } = 1;
        }
    }
    print "$file completed\n";
}

print "$_\n" for ( sort { uc( $a ) cmp uc( $b ) } keys %umlautWords );


Editiert von FIFO: Kosmetik
Last edited: 2014-03-19 12:50:10 +0100 (CET)
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"

View full thread Vokale im Umlaute wandeln