Thread Präfixe rausschreiben (7 answers)
Opened by Philipp at 2012-04-29 13:14

FIFO
 2012-04-29 15:52
#157942 #157942
User since
2005-06-01
469 Artikel
BenutzerIn

user image
z.B. so (ungetestet):

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
use warnings;
use strict;

my @new_lines;

while (my $line = <DATA>) {
    my ($key, $prefix, $extension) = $line =~ /\A(.+?)\t(\d+)(?:\((.+?)\))?/;
    if (defined $extension) {
        my @extensions = split(/,/, $extension);
        for my $item (@extensions) {
            if ($item =~ /(\d+)-(\d+)/) {   # erste Zahl muss kleiner sein
                for my $i ($1..$2) {
                    push @new_lines, "$key\t$prefix$i";
                }
            }
            else {
                push @new_lines, "$key\t$prefix$item";
            }
        }
    }
    else {
        push @new_lines, "$key\t$prefix";
    }
}
print "$_\n" for sort(@new_lines);

__DATA__
201.1   201(27,28,3,4,83,84,890,897,898,9)
201.1   2054
201.2   201(1,20-26,29,80-82,891-896,899)
201.3   201(52-54,6,75,76,85-88)
201.4   201(50,51,55-59,70-74,77-79)
202.1   202(20-24,28,29,4,75,8,90-92,94,95,97-99)
202.2   202(1,27,3,70-74,76-79,93)
202.3   202(25,26,5,6,96)
203.1   203(1-3,41-45,9)
203.1   206
203.2   203(40,46-49,5,8)
203.3   203(6,7)
2041.1  204
2051.1  2051
2051.1  2052
2051.1  2053
2051.1  2056
2051.1  2058


Editiert von FIFO: Fall ohne $extension fehlte

Editiert von FIFO: print aus der Schleife gerettet :)
Last edited: 2012-04-29 16:53:21 +0200 (CEST)
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 Präfixe rausschreiben