[LA.pm] alternating...

Peter Benjamin pete at peterbenjamin.com
Sat Jun 25 13:00:21 PDT 2005


A case to try perl -d to see code execution order,
as I can not see what is wrong via visual inspection
and it worked for me with this initialization:

my @mem = (
"1",
"2",
"3",
"4",
"5",
"6",
"7",
);

I do suggest you avoid variable names that might conflict
with reserved words, as "$line" might do in some languages,
just on general principles.  Same with mem, which is an unix
command.

Post your test data for @mem would be good.

Starting $color as uninitialized is not wise, imo.

Also, try perl -w  and strict for more detailed error messages.

Trick: avoid \" inside of double quoted strings by using just '

-p


At 12:34 PM 6/25/2005, 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