in reply to Re: alternating row colors
in thread alternating row colors

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.

Replies are listed 'Best First'.
Re: Re: Re: alternating row colors
by Kanji (Parson) on May 18, 2001 at 04:02 UTC

    Personally, I'd find ...

        $colors[ $row++ % @colors ]

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

        --k.


Re^3: alternating row colors
by Anonymous Monk on Jun 09, 2010 at 18:30 UTC
    Out of all the code written .. this may be the best simple version.