in reply to Re: Anyone use "xor" in conditionals?
in thread Anyone use "xor" in conditionals?

Hehe, whenever I use flipflops I confuse the cow orkers. However, I've always written it differently:
my $flipflop = 1; for my $row_ref ( @$ary ) { ... $flip_flop = 1 - $flipflop; }
I'm not sure that this is potentially more efficient in Perl (probably less efficent?), but is an idiom I remember from my Amiga asm days. Personally, I also think it's easier to see what's going on too :)

Replies are listed 'Best First'.
Re: Re: Re: Anyone use "xor" in conditionals?
by Cody Pendant (Prior) on Jul 14, 2003 at 11:24 UTC

    I'm a bit confused by these flipflops being used, as well as the ternary thing, to alternate colours.

    I long ago whittled it down to just

    $bgcolor = ($bgcolor eq 'white'?'black':'white');
    which flips itself.

    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D
      Check out Tie::Toggle:
      use Tie::Toggle; tie my $toggle, 'Tie::Toggle'; my @color = qw(black white); print "$color[$toggle]\n" for 1..10;
      Using more than one color? Tie::Cycle
      use Tie::Cycle; tie my $color, 'Tie::Cycle', [qw(red white blue)]; print "$color\n" for 1..10;
      Combine that with Color::Spectrum:
      use Tie::Cycle; use Color::Spectrum qw(generate); tie my $color, 'Tie::Cycle', [generate(4,'#ff00ff','#00ff00')]; print "$color\n" for 1..10;

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
        Or Tie::FlipFlop:
        use Tie::FlipFlop; tie my $flipflop => 'Tie::FlipFlop', qw /black white/; print $flipflop; # black print $flipflop; # white print $flipflop; # black print $flipflop; # white

        Abigail