in reply to Re: Re: Editing Entries In A Flat Database
in thread Editing Entries In A Flat Database with cgi

Perhaps you're right. That was a bad example. One way CGI.pm shows its usefulness which seems to been obscured here is with deeply nested constructs (table within a table within a form, etc.).

By replacing the BEGIN/END (tag) paradigm with a nested function call paradigm, CGI all but eliminates the kind of unbalanced tag nuisances one frequently encounters when generating HTML dynamically.

IMHO, I find looking at naked HTML (in a HEREDOC or otherwise) annoying for its waste of space (I suppose XML rubs me much the same way) and its near-redundancy; I dislike typing it even more.

I suppose the advantage is better illustrated with this comparison:

<FORM METHOD='POST> <INPUT TYPE="hidden" NAME="mode" VALUE="confirm"> <TABLE BORDER=0> <TR> <TD> <TABLE WIDTH='100%'> <TR> <TH>ColA</TH> <TH>ColB</TH> <TH>ColC</TH> </TR> <TR> <TD>Value A</TD> <TD>Value B</TD> <TD>Value C</TD> </TR> <TR> <TD><INPUT TYPE="submit"></TD> <TD><INPUT TYPE="reset"</TD> <TD>&nbsp;</TD> </TR> </TABLE> </TD> </TR> </TABLE> </FORM>

Compared with:

form( { -method => 'POST' }, hidden( -name => 'mode', -value => 'confirm' ), table( { -border => 0 }, Tr( td( table( { -width => '100%' }, Tr( th( [ 'ColA','ColB','ColC' ] ), td( [ 'Value A','Value B','Value C' +] ) td( [ submit, reset, '&nbsp;' ] )) ))) ) )

Oh, you want to write all that to the browser?

print form( { -method => 'POST' }, hidden( -name => 'mode', -value => 'confirm' ), table( { -border => 0 }, Tr( td( table( { -width => '100%' }, Tr( th( [ 'ColA','ColB','ColC' ] ), td( [ 'Value A','Value B','Value C' +] ) td( [ submit, reset, '&nbsp;' ] )) ))) ) )

dmm

You can give a man a fish and feed him for a day ...
Or, you can
teach him to fish and feed him for a lifetime

Replies are listed 'Best First'.
Re (tilly) 4: Editing Entries In A Flat Database
by tilly (Archbishop) on Jan 05, 2002 at 19:31 UTC
    For any complex website I would strongly disagree with the advice to use CGI's html generation methods. The more complex the overall site, the more I tend to disagree. A recent node with a good summary of why templating is a good idea was given by maverick at Re: Re: Re: Re: Code Critique. (There are plenty of others out there of course.)
      "For any complex website I would strongly disagree with the advice to use CGI's html generation methods."

      Depending upon the level of complexity, I would tend to agree with your assessment, although for my own work, I tend to mix and match. For instance, I might template the site look-and-feel components (top or left navbar, etc.) especially if I need a lot of Javascript to glue it all together, but for low- to medium-complexity screens, I sometimes choose to use CGI.pm exclusively for generating the HTML.

      I find that for highly dynamic screens, CGI.pm is easier to work with than, say Dreamweaver and the like. It rarely takes more than a couple of iterations to tweak it into shape.

      My .02.

      dmm

      You can give a man a fish and feed him for a day ...
      Or, you can
      teach him to fish and feed him for a lifetime