in reply to Re: help with start_table of CGI.pm
in thread help with start_table of CGI.pm

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: help with start_table of CGI.pm
by davorg (Chancellor) on Feb 02, 2007 at 16:00 UTC

    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.