in reply to if logic OR parentheses problem
First of all, that isn't your code -- here's what perltidy and the Perl compiler would like it to be:
#!/usr/bin/perl -w use strict; { my $a = 20; my $b = 22.5; my $c = 23; my $atob = $a - $b; my $btoc = $b - $c; my $atoc = $a - $c; my @matrixflags; if ((($atob > 1) || ($atob < -1)) && (($atoc > 1) || ($atoc < -1)) && (($btoc > 1) || ($btoc < -1))) { print OUTFILE "DIFF > 1 all three\n"; $matrixflags[$row - 4][$i] = 1; $matrixflags[$row - 3][$i] = 1; $matrixflags[$row - 2][$i] = 1; } elsif ((($atob > 1) || ($atob < -1)) && (($btoc < 1) && ($btoc > -1)) && (($atoc > 1) || ($atoc < -1))) { print OUTFILE "DIFFA > 1 $atob $atoc $btoc\n"; $matrixflags[$row - 4][$i] = 1; $matrixflags[$row - 3][$i] = 0; $matrixflags[$row - 2][$i] = 0; } elsif ((($atob > 1) || ($atob < -1)) && (($btoc > 1) || ($btoc < -1)) && (($atoc < 1) && ($atoc > -1))) { print OUTFILE "DIFFB > 1 $atob $atoc $btoc\n"; $matrixflags[$row - 4][$i] = 0; $matrixflags[$row - 3][$i] = 1; $matrixflags[$row - 2][$i] = 0; } elsif ((($atob < 1) && ($atob > -1)) && (($btoc > 1) || ($btoc < -1)) && (($atoc > 1) || ($atoc < -1))) { print OUTFILE "DIFFC > 1 $atob $atoc $btoc\n"; $matrixflags[$row - 4][$i] = 0; $matrixflags[$row - 3][$i] = 0; $matrixflags[$row - 2][$i] = 1; } #So in this example in my head the 1st elsif should be executed. #Difference $atob = 1.5 so (($atob > 1) || ($atob < -1)) is true. #Difference $btoc = 0.5 so (($btoc < 1) && ($btoc > -1)) is true. #Difference $atoc = 3 so (($atoc > 1) || ($atoc < -1)) is true. }
Secondly, even that throws errors -- neither $row or $i are defined (either using my or programmatically). Why not show us a fragment of code that at least compiles and runs, then we'll be able to help you.
|
|---|