etherald:

If you break your condition down into chunks you should be able to see the problem. You can do it something like this:

#!/usr/bin/perl use strict; use warnings; for my $lines (0 .. 4) { print "lines=$lines: "; print $lines ? "A " : " "; print $lines%2 ? "B " : " "; print $lines && $lines%2 ? "C " : " "; print $lines>3 ? "D " : " "; print $lines==3 ? "E " : " "; print( ($lines>3 or $lines==3) ? "F " : " "); print( (($lines && $lines%2) or ($lines>3 or $lines==3)) ? "G " : +" "); print "\n"; }

When you run it, it'll print a truth table of the various bits of your expression. If your whole expression is true, you'll get a G on the row. (Note: "C" is the result of the bit in your first set of parenthesis, and "F" is for the bit in the right pair of parenthesis.) Running it give you:

$ perl t.pl lines=0: lines=1: A B C G lines=2: A lines=3: A B C E F G lines=4: A D F

So when $lines==1, you get a G because the first condition is satisfied. If you change the or between your parenthesis to and, you'll get what you want.

Even so, your expression is too complicated for what you want. You really want to keep it if it's an odd number greater than or equal to three, right? If so you want:

$lines%2 and $lines>=3

Note: $lines=3 is an assignment rather than a conditional, so I changed it to $lines==3.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: getting my value as i like it to by roboticus
in thread getting my value as i like it to by etherald

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.