use warnings; use strict; $| = 1; my @categories = ( 'V=aeiou', 'P=pbtdkg', 'N=12345' ); my %categ_hash = map { split /=/ } @categories; # ('V' => 'aeiou', ...) my $categ_types = join('', keys %categ_hash); # 'VPN' my $categ_types_rx = qr{ \A [$categ_types] \z }x; # \A[VPN]\z while (1) { print "Text: "; my $text = ; chomp($text); last if ! $text; print "Regel: "; my $rule = ; chomp($rule); last if ! $rule; my $rule_err = rule_check($rule); if ($rule_err) { print "Regel fehlerhaft: $rule_err\n"; next; } my $processed_text = process_text($text, $rule); print "\nNach Ersetzung: $processed_text\n\n"; } sub rule_check { my $rule = shift; # Hier Regelsyntax prüfen! return 0; # fehlerfrei } sub process_text { # build_regex($rule); my ($text, $rule) = @_; my ($to_replace, $replace_with, $pattern) = split('/', $rule); my $processed = $text; # Sonderfall translate (z.B. Regel V/N/_), das $pattern wird ignoriert if ($to_replace =~ $categ_types_rx and $replace_with =~ $categ_types_rx) { $to_replace = $categ_hash{$to_replace}; $replace_with = $categ_hash{$replace_with}; print ("tr/$to_replace/$replace_with/\n"); if (length($to_replace) != length($replace_with)){ warn "Ungleiche Zeichenzahl in Kategorien.\n"; } else { local $_ = $processed; eval "tr/$to_replace/$replace_with/"; $processed = $_; } return $processed; } for my $category (@categories) { my ($type, $class) = split('=', $category); $pattern =~ s/$type/[$class]/g; $to_replace =~ s/$type/[$class]/g; } $pattern =~ s/(.+)_/(?<=$1)_/; $pattern =~ s/_(.+)/_(?=$1)/; $pattern =~ s/_/$to_replace/; $processed =~ s/$pattern/$replace_with/g; return $processed; } __END__