in reply to if logic OR parentheses problem

If you add the line:
print join ' ', $atob, $btoc, $atoc, "\n";
You'll notice that $atob is -2.5, $btoc is -0.5, and $atoc is -3.

For clarity, I'd also use the abs function rather than nested logic:

if (abs $atob > 1 && abs $btoc > 1 && abs $atoc > 1 ) { print OUTFILE "DIFF > 1 all three\n"; $matrixflags[$row - 4][$i] = 1; $matrixflags[$row - 3][$i] = 1; $matrixflags[$row - 2][$i] = 1; } elsif (abs $atob > 1 && abs $btoc < 1 && abs $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 ( ... ) { ... }
And like the other monks suggested, use strict; and use warnings; will point out where your code could run into problems. There is also use diagnostics; for an extra helping of advice.

Replies are listed 'Best First'.
Re^2: if logic OR parentheses problem
by johngg (Canon) on Oct 26, 2007 at 15:40 UTC
    print join ' ', $atob, $btoc, $atoc, "\n";

    Why use join? It's far simpler to interpolate inside double-quotes.

    print qq{$atob $btoc $atoc\n};

    Cheers,

    JohnGG

    Update: Corrected sigil typo

      I use join like this all over the place. In many cases, I find that it looks less cluttered in the code. There's no great advantage to it in this case, but there's no reason to avoid it either.