Thread (Verständnis)Probleme mit verschachtelten foreach-Schleifen und If-Abfragen
(11 answers)
Opened by Wurzel at 2008-08-07 19:28
Du brauchst keine eigene for-Schleife, um die Arrays der verbotenen Werte zu durchwandern.
Ein einfaches grep sollte reichen, um zu kontrollieren, ob der aktuelle Wert einem "verbotenen" Wert entspricht. 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 #!/usr/bin/perl -w use strict; my @konsonants = qw( p b t d k g m n f v h ch l r s sch ts ds tsch dsch x ); #21 my @not_first = qw( p b t d k g ); #6 my @not_second = qw( p b t d k g m n ts ds tsch dsch x ); #13 foreach my $konso1 (@konsonants) { next if ( grep { $konso1 eq $_ } @not_first ); foreach my $konso2 (@konsonants) { next if ( $konso1 eq $konso2 ); next if ( grep { $konso2 eq $_ } @not_second ); print $konso1, $konso2, $/; } } meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen! |