in reply to comparison with bitwise operators

if( 3-2 == abs( 3+2 - 2*$var ) ) { # q-: }

If you have 3 values, it takes slightly more work:

if( not $var**3 - 12*$var**2 + 41*$var - 42 ) { # $var is 2, 3, or 7 }

For the specific case of 2 and 3:

if( 3 == ( $var | 1 ) ) {

- tye        

Replies are listed 'Best First'.
Re^2: comparison with bitwise operators (horror)
by ikegami (Patriarch) on Jan 13, 2011 at 22:04 UTC

    That reminds me of the time I had to debug this old BASIC game that used hundreds of expressions like

    y = 4 - (x > 3) * 2

    to achieve

    $y = $x > 3 ? 6 : 4;

    Some assignments even had more than one such conditional per line. It was hell.

    (True was -1)