in reply to Ternary if versus normal if question

And yet, why not $lights[$light] = !$lights[$light];

-M

Free your mind

Replies are listed 'Best First'.
Re^2: Ternary if versus normal if question
by ysth (Canon) on Nov 18, 2005 at 05:07 UTC
    Or, more succinctly, $lights[$light] ^= 1;.

      Beware of strings vs numbers, though. The bitwise ops in Perl are hazardous if used imprudently.

      Makeshifts last the longest.

      I looked for a solution with ^=, but it doesn't work unless it can be made into a unary operator at which point I gave up looking down that route. Your suggestion only turns the light on when off but does not turn it off when on.

      -M

      Free your mind

        $ perl -wle '$a=0; $a ^= 1; print $a' 1 $ perl -wle '$a=1; $a ^= 1; print $a' 0