Okay first of all I started by making a prototype with this code.
#!/usr/bin/perl -w use strict; my @array = qw(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 +9 20); my $rows = 2; my $row_count = 0; my $array_total = 7; print "[START]\n"; for(my $i = 1; $array_total >= $i; ++$i) { if ($row_count == 0) { $row_count += 2; print "$array[$i] "; } elsif ($i == $array_total) { print "$array[$i]"; } elsif ($rows == $row_count) { $row_count = 0; print "$array[$i]\n"; } else { ++$row_count; print "$array[$i] "; } } print "\n[END]\n";
Which works fine when you change $rows or $array_total, then when I went to implement that into my code I came up with something like this
#!/usr/bin/perl -w use strict; my $total_sites = 7; my $row_count = 0; my $rows = 2; print "<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacin +g=\"3\">\n\n"; for(my $i = 1; $total_sites >= $i; ++$i) { if ($row_count == 0) { $row_count += 2; print " <tr valign=\"top\">\n <td width=\"100%\">\n"; print " number: [$i]\n"; print " </td>\n\n"; } elsif ($i == $total_sites) { print " <td width=\"100%\">\n"; print " number: [$i]\n"; print " </td>\n\n"; } elsif ($rows == $row_count) { $row_count = 0; print " <td width=\"100%\">\n"; print " number: [$i]\n"; print " </td>\n\n </tr>\n\n"; } else { print " <td width=\"100%\">\n"; print " number: [$i]\n"; print " </td>\n\n"; } } print " </tr>\n\n</table>\n";
The problem is if $rows is anything other than 2 it doesn't work, I can't figure out why it's not doing the block
} elsif ($rows == $row_count) { $row_count = 0; print " <td width=\"100%\">\n"; print " number: [$i]\n"; print " </td>\n\n </tr>\n\n";
to print out the close table row tag like it does with the first script for the newlines.

Edit kudra, 2002-01-10 Changed title


In reply to Loop counter only works for 2 by rendler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.