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

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

Replies are listed 'Best First'.
(jeffa) 4Re: Anyone use "xor" in conditionals?
by jeffa (Bishop) on Jul 14, 2003 at 13:51 UTC
    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