Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: alternating row colors

by BigJoe (Curate)
on May 18, 2001 at 00:59 UTC ( [id://81369]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found