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

problems using dynamic tables in perl cgi

by polki (Novice)
on May 13, 2009 at 13:28 UTC ( #763750=perlquestion: print w/ replies, xml ) Need Help??
polki has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I'm having a problem with Perl CGI creating tables of previously unknown length. This is what the doc says about the usage:
print table({-border=>undef}, caption('When Should You Eat Your Vegetables?'), Tr({-align=>CENTER,-valign=>TOP}, [ th(['Vegetable', 'Breakfast','Lunch','Dinner']), td(['Tomatoes' , 'no', 'yes', 'yes']), td(['Broccoli' , 'no', 'no', 'yes']), td(['Onions' , 'yes','yes', 'yes']) ] ) );
From this I followed, that the Tr command takes a hash as first parameter and an array containing the tds as second parameter. Please correct me if I'm wrong there.
Now that's what I did ($c is my CGI object): I pushed several values onto an array
... iterate over results from database request ... { push (@rows, $c->td([$firstvar, $secondvar, $thirdvar])); }
Later the same day:

print $c->table( {-border=>'0',-align=>'Center'}, $c->Tr({-align=>'Left'}, @rows) );

Unfortunately the result is no nice table, but instead a flat table with all values in one row...
So where is the crash in my thoughts?

Comment on problems using dynamic tables in perl cgi
Select or Download Code
Re: problems using dynamic tables in perl cgi
by explorer (Chaplain) on May 13, 2009 at 13:40 UTC

    You need a new deep level of reference:

    print $c->table( {-border=>'0',-align=>'Center'}, $c->Tr({-align=>'Left'}, [ @rows ]) );

      Thanks very much! That did it... :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://763750]
Approved by tbone1
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-07-24 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls