in reply to Editing Entries In A Flat Database with cgi

Some comments:

Replies are listed 'Best First'.
Re: Re: Editing Entries In A Flat Database
by impossiblerobot (Deacon) on Dec 28, 2001 at 20:33 UTC
    It seems to me that everytime someone advocates using CGI.pm for HTML generation, they give examples that show (IMHO) no advantage over printing HTML in a 'heredoc'.

    I have found many cases where CGI.pm HTML functions are very useful (such as generating checkbox groups from data), but in cases like this, I find the HTML more readable.

    Impossible Robot
      IMHO there should be no HTML in Perl code at all. Neither in form of heredocs nor in form of CGI.pm method calls. Use templates!

      --
      Ilya Martynov (http://martynov.org/)

      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
        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.)