[LA.pm] alternating...
William Reardon
wdr1 at pobox.com
Sat Jun 25 13:08:25 PDT 2005
Your snippet by itself works, so you must be doing something wrong
elsewhere in the script. Are you messing with $line anywhere? Make
sure you have warnings on ("use warnings" at the top) and see what
that says.
Here's an easier way to do the same thing, using the modulo operator:
my @mem = qw|foo bar baz bang bong bing ding dong dang|;
my $n = 0;
foreach my $line (@mem) {
print '<TR><TD BGCOLOR="',
$n++ % 2 ? '#93c0c0' : '#cae8ff',
"<A HREF='$line'>$line</A></TD></TR>\n\n";
}
HTH,
-Bill
At 3:34 PM -0400 6/25/05, David Heayn wrote:
>I'm trying to alternate between printing dark blue rows of an HTML
>table and just blue rows. However, I'm not getting the results I
>want. In fact, I even know why the below code doesn't work. If you
>have any suggestions on how to switch between two colors on table
>rows I would love to hear it.
>
>foreach my $line (@mem)
> {
> if ($color == 0)
> {
> print "<tr><td bgcolor=\"#93c0c0\">";
> $color = 1;
> }
> elsif($color == 1)
> {
> print "<tr><td bgcolor=\"#cae8ff\">";
> $color = 0;
> }
>
> print "<A HREF=\"$line\">$line</A></TD></TR>\n\n";
> }
>
>
>
>
>
>btw- This is the meat of what the script prints out:
>
>
>
><tr><td bgcolor="#93c0c0"><A HREF="http://">http://</A></TD></TR>
># this loop went well
><tr><td bgcolor="#cae8ff"><A HREF="http://">http://</A></TD></TR>
># another good one...
><tr><td bgcolor="#93c0c0"><tr><td bgcolor="#cae8ff"><tr><td
>bgcolor="#93c0c0"><A HREF="http://">http://</A></TD></TR>
># problems here... double TR's
><tr><td bgcolor="#cae8ff"><tr><td bgcolor="#93c0c0"><tr><td
>bgcolor="#cae8ff"><tr><td bgcolor="#93c0c0"><tr><td
>bgcolor="#cae8ff"><tr><td bgcolor="#93c0c0"><tr><td
>bgcolor="#cae8ff"><tr><td bgcolor="#93c0c0"><A
>HREF="http://">http://</A></TD></TR>
>#lots of problems here... 7 TR tags before getting to what's important.
>
>
>I hope this is all clear.
>
>
>
>David Heayn * http://www.cloudgraphics.com * 213/925.3283
>_______________________________________________
>Losangeles-pm mailing list
>Losangeles-pm at pm.org
>http://mail.pm.org/mailman/listinfo/losangeles-pm
More information about the Losangeles-pm
mailing list