in reply to Searching for Patterns in CSV
Not sure though that this implements the logic that you want. Your Python program does not do the same thing as the Perl one-liner, so I don't really know what you want. If you want to test for each value in the (1..3) range and print if none of the conditions matched then it should rather something like this:while (my $line = <$file>) { chomp $line; # remove trailing end of line character my @F = split /,/, $line; for my $i (1..3) { if ($F[0]+ $i == $F[1] and $F[1]+$i == $F[2]) { warn "row $.: $_\n"; } else { print $line, "\n"; } } }
LINE: while (my $line = <$file>) { chomp $line; my @F = split /,/, $line; for my $i (1..3) { if ($F[0]+ $i == $F[1] and $F[1]+$i == $F[2]) { warn "row $.: $_\n"; next LINE; # the condition matched, go immediately to the +next input line, do not print } } print $line, "\n"; }
|
|---|