Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Anyone use "xor" in conditionals?

by kal (Hermit)
on Jul 14, 2003 at 09:33 UTC ( [id://273921]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://273921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-18 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found