in reply to alternating row colors

my @colors=( '#FFFFFF', '#DDDDFF' ); my $row = 0; while ( @data = ... ) { my $rowcolor = $colors[ $row++ % 2 ]; print ... }

Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: alternating row colors
by BigJoe (Curate) on May 18, 2001 at 00:59 UTC
    Good code but you could make it a little bit more open by removing the 2 and replace it with $#colors
    my @colors=( '#FFFFFF', '#DDDDFF' ); my $row = 0; while ( @data = ... ) { my $rowcolor = $colors[ $row++ % ($#colors + 1) ]; print ... }
    Then if you would like to add more colors to rotation you do not need to change anything besides adding the color.

    --BigJoe

    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.

      Personally, I'd find ...

          $colors[ $row++ % @colors ]

      ... easier on the eyes, but aesthetics are always subjective. :)

          --k.


      Out of all the code written .. this may be the best simple version.