Thread grep und Teilstring (13 answers)
Opened by Benjamin at 2014-07-16 14:08

pq
 2014-07-16 15:07
#176476 #176476
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
Guest Benjamin
Vielen Dank!

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
my @list = w/ 12 11 10 08 07 04 00 94 91 90 87 67 24 /;
if (grep $a =~ /_($_)$/, @list) {
if ((grep($a =~ /^$_/, (16, 24, 25, 34)) && ($tbvartyp || 2003) != 2003) ||
(grep($a =~ /^$_/, (43, 44, 63, 64)) && ($tbvartyp || 2002) != 2002) ||
(grep($a =~ /^$_/, (56)) && ($tbvartyp || 2004) != 2004) ||
(grep($a =~ /^$_/, (70, 75, 77, 78)) && ($tbvartyp || 2001) != 2001)) {
push @comments, "matched";
}
}
else {
if (($a =~ /^56/ && ($tbvartyp || 2004) != 2004) ||
($a !~ /^56/ && ($tbvartyp || 2003) != 2003)) {
push @comments, "matched";
}
}
}


du machst es dir echt schwer.
statt mehrere zahlen zu durchlaufen, schreib doch einfach:
Code (perl): (dl )
1
2
3
4
         if (($a =~ m/^(16|24|25|34)$/ && ($tbvartyp || 2003) != 2003) ||
             ($a =~ m/^(43|44|63|64)$/ && ($tbvartyp || 2002) != 2002) ||
             ($a =~ m/^(56)$/          && ($tbvartyp || 2004) != 2004) ||
             ($a =~ m/^(70|75|77|78)$/ && ($tbvartyp || 2001) != 2001)) {
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread grep und Teilstring