Hello Monks,
I am rewriting a web form, because the old form hard coded *everything*, and I am trying to make it a bit more dynamic and flexible. The form allows folks to update stuff stored in an AoA called @champarray in the code below. I have it dynamically generating a table with all the items, but I want to make it break the rows up, so that there are not more than five tds per tr (so that the page does not get absurdly wide), somehow nothing reasonable is entering my mind when I think about this, and I think I must be missing an obvious solution. I created a $rownum var that determined how many rows to subdivide in, but then did not really know what to do with it. The code below is a little funny looking since I am still in the middle of thinking about this. In the context of this code, what is the best way to iterate by fives to fill the rows? Any other constructive criticism would also be appreciated.
The relevant chunk:
my $productcount = 0;#index of which product we are using
print $q->table({-border=>1});
foreach (@champarray){# go through each item.
my @rows;
my @tmp_row_items = $q->p($champarray[$productcount][0]);#item 0 i
+n array is the name of our item
my $itemnum = $#{$champarray[$productcount]};
my $rownum = ceil($itemnum / 5);#ceil is POSIX round up function
for my $i (1 .. $itemnum){
push (@tmp_row_items, $q->td($q->textfield( -name => "$champar
+ray[$productcount][0]$i", -default => "$champarray[$productcount][$i]
+", -size => 25)));
}
push (@rows, $q->td(@tmp_row_items));
print $q->Tr(\@rows);
$productcount++;
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.