Thread Tastatureingabe vorgeben (8 answers)
Opened by OlliP at 2023-08-02 14:43

hlubenow
 2023-08-02 18:26
#195220 #195220
User since
2009-02-22
875 Artikel
BenutzerIn
[default_avatar]
Hab's mal ausgeschrieben. War'n bißchen tricky, hat aber bei diesem August-Regenwetter auch Spaß gemacht.
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl

use warnings;
use strict;

my $text = <<'END_MESSAGE';

Steuer-Apps fuers Smartphone versprechen eine moeglichst einfache und schnelle Steuererklaerung innerhalb von Minuten und hohe Rueckzahlungen von ueber 1000 Euro im Schnitt.
Die Abgabe erfolgt digital per Knopfdruck, es gibt keinen Papierkram mehr, und nach ein paar Wochen soll das Geld schon da sein:
Gemuetlich Steuern machen vom Sofa aus.

Wir haben sechs dieser Steuer-Apps aus Deutschland getestet.
Klartax, Steuerbot, Steuer Go, Taxfix, Wiso Steuer und wundertax sind gleichermaszen dafuer geeignet, eine Steuererklaerung abzugeben.
Dennoch taten sich deutliche Unterschiede auf, nicht nur, was die Einfachheit und Unterstuetzung für Steuerlaien betrifft, sondern auch was die Abrechnung selbst angeht.

END_MESSAGE

my @lines = split(/\n/, $text);

sub setBright {
    print "\033[1m";
}

sub setNormal {
    print "\033[0m";
}

sub processLine {
    my $line = shift;
    my @searches = qw(ae oe ue Ae Oe Ue sz);
    my %replaces = (ae => "ä",
                    oe => "ö",
                    ue => "ü",
                    sz => "ß");
    my ($c, $cn, $i, $input, $result);
    my @positions  = ();
    my @a          = ();
    my $cursor = 0;
    my @pieces = ();
    my $start  = 0;
    my $l = length($line);
    while ($cursor < $l) {
        $c = substr($line, $cursor, 1);
        if ($cursor == $l - 1) {
            $cn = "";
        } else {
            $cn = substr($line, $cursor + 1, 1);
        }
        for $i (@searches) {
            if ("$c$cn" eq $i) {
                push(@positions, $cursor);
                push(@a, $i);
            }
        }
        $cursor++;
    }

    for $i (@positions) {
        push(@pieces, substr($line, $start, $i - $start));
        $start = $i + 2;
    }
    push(@pieces, substr($line, $start));

    if ($#positions == -1) {
        return $line;
    }

    print "Starting editing: \n\n";

    for $i (0 .. $#positions) {
        $result .= $pieces[$i];
        print substr($line, 0, $positions[$i]);
        setBright();
        print $a[$i];
        setNormal();
        print substr($line, $positions[$i] + 2);
        print "\n\n";
        print "Change \"$a[$i]\" (y/n)? ";
        $input = <STDIN>;
        chomp($input);
        if ($input eq "y") {
            $result .= $replaces{$a[$i]};
        } else {
            $result .= $a[$i];
        }
        if ($input eq "q") {
            print "Bye.\n";
            exit 0;
        }
        print "\n";
    }
    $result .= pop(@pieces);
    return $result;
}

my $linenr = 0;
my $result;
my $input;
my @results = ();
while ($linenr <= $#lines) {
    print "Line " . ($linenr + 1) . " of ". ($#lines + 1) . ". ";
    $result = processLine($lines[$linenr]);
    print "\nLine:\n\n$result\n\n";
    print "Keep line (y/n)? ";
    $input = <STDIN>;
    chomp($input);
    if ($input eq "y") {
        push(@results, $result);
        $linenr++;
    }
    if ($input eq "q") {
        print "Bye.\n";
        exit 0;
    }
    print "\n";
}

my $i;
print "Result: \n";
for $i (@results) {
    print "$i\n";
}

View full thread Tastatureingabe vorgeben