http://qs321.pair.com?node_id=235626


in reply to How to iterate by fives?

I think the solution for this is going to be pretty difficult and exteremely ugly html. Let's say the first entry in @champarray has a total of 5 items. Perfect: it'll all fit in one row with 5 columns. Now, say the second entry has 7 entries. You'll fill one row and then 2 columns of the next row. That'll leave you with 3 empty columns in that second row, so in order to create valid html, you'll have to output a print td() x 3;. So yes, this would be possible, but I guarantee it'll look ugly in code, in html and visual table output. Blank cells all over just wouldn't look very appealing.

So is there no help for this? Of course there is! What I wholeheartedly propose is rather than filling columns like this, use rows. Here's some code that creates very appealing output. Code is tested, because I wasn't too sure of myself :) I really hope you consider using something based on the below code. It looks nicer, it's easy html and it's better! I changed the variable names, just because I didn't like the ones you were using :)

#!/usr/bin/perl -Tw use strict; use CGI qw/:standard *table/; my @products = ( ['Dog', 'Rover', 'Hairy', 'Smelly'], ['Cat', 'Snowball', 'Sharp', 'Smelly'], ['Mouse', 'Mousey', 'Tiny', 'Cheese'] ); print header(), start_html('Product Info'), start_table( {cellpadding=>5,border=>2,align=>'center'} ); for my $product (@products) { print Tr( th( {align=>'left'}, 'Product ID/Name:' ), td( $product->[0] ) ); my $i; for my $entry (@{$product}) { next if ++$i == @{$product}; print Tr( td( '    Entry #', $i, ':' ), td( textfield( {name=>$product->[0].$i,value=>$product->[$i],size=>25} ) ) ); } print Tr( td( {colspan=>2}, p() ) ); } print end_table(), end_html();


If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.