If the confusion was caused by the difference between CGI (the class name) and $CGI (the variable containing an instance of that class) then perhaps you should be a bit more careful in how you name your variables. Or perhaps you should consider using the functional interface to CGI.pm.

I want to use $CGI->tr to generate a row of my table, and I want to give it an array which contains all of the cells that I want in that row. Each cell will just contain a string. There should be a way to do this, I don't know how, and would love to have documentation somewhere that tells me how to do things like this.

Several times you have been given links to the section in the documentation about the distributive property of HTML shortcuts. That seems to tell you everything that you need to do.

If you pass a list of arguments to an HTML shortcut function (like td()). Then it does what you expect.

use CGI ':html'; # functional interface my @row = qw(one two three four five); print Tr(td(@row)); # prints <tr><td>one two three four five</td></tr>

If, however, you pass a reference to an array, then you get slightly different behaviour.

use CGI ':html'; # functional interface my @row = qw(one two three four five); print Tr(td(\@row)); # prints <tr><td>one</td> <td>two</td> <td>three</td> <td>four</td> <t +d>five</td></tr>

It's this second behaviour that you want. It's called distributive behaviour because the tag is distributed across the elements in the array. The documentation that you were pointed at even contained an example of how to do it.


In reply to Re^3: help with start_table of CGI.pm by davorg
in thread help with start_table of CGI.pm by kmullin5016

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.