Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to iterate by fives?

by Coruscate (Sexton)
on Feb 15, 2003 at 23:31 UTC ( [id://235626]=note: print w/replies, xml ) Need Help??


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.

Replies are listed 'Best First'.
Re: Re: How to iterate by fives?
by moof1138 (Curate) on Feb 16, 2003 at 00:25 UTC
    Thanks for the ideas. This is pretty much in line with what I had originally made, since it certainly is simpler to generate, but the original I am replacing has items in colums, and I need it to be as transparent an update as I can make it. The form tracks email addresses of folks associated with certain products. There are currently about fourty products with five to ten email addresses associated with a number of them, so it wound up appearing really clumsy to me. Since the number of products will only increase, and one of the reasons I was rewriting it was because there was a hard limit of ten, and we had cases where up to twenty email addresses would be needed, with the possibility of this increasing even more over time, which starts to get really awkward in one giant column.

    I am not really an html guy, I was not aware that a different number of columns/row in a table was invalid. The stuff I generated renders correctly in all the browsers I need to test, but I will have to consider adding blank cells, since I want it to be correct. Since I have no borders on the table anyway, a blank cell and no cell have basically the same appearance. Again thanks.
      In your HTML, you may need to put &nbsp; in the empty <td> elements in order for the blank space to be 'filled in' by the browser. YMMV.

      This observation is based on purely anecdotal evidence; I hope it turns out to be more than just a brain-fart.

        You're right. Some browsers will not render a table cell if it has nothing in it. What I tend to do, rather than using a &nbsp;, is to put in a one-pixel, transparent image tag, so that if the cell wants to be narrower or shorter than the nbsp it can be.

        LAI
        :eof

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://235626]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-18 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found