CGI.pm vs HTML

CGI.pm is a tool that sugarcoats the writing of html for programmers. It's not strictly necessary, but does blur the distinction between mark-up and code.

Benefits of CGI

CGI makes writing HTML nicer, as a general rule - that is its purpose, after all. This means that there are some really nice HTML shortcut properties to achieve maximum efficiency.

For instance - the distributive property. Instead of writing out something like:

<Tree>
   <tr align="center">
      <td>
         red
      </td>
      <td>
         green
      </td>
      <td>
         blue
      </td>
   </tr>
   <tr align="center">
      <td>
         purple
      </td>
      <td>
         yellow
      </td>
      <td>
         orange
      </td>
   </tr>

You can instead write out (bringing in familiar array syntax):

  print table(
           tr({-align=>'center'},
           [
              td(['red', 'green', 'blue']),
              td(['purple', 'yellow', 'orange']),
           ]
           )
        );

Benefits of HTML

  • Can format your html - spacing and ordering, it's all self-defined
  • You don't have to learn a whole new language - html is intuitive because it's simple
  • There are some things where cgi.pm is just unnecessary - links are the same, text boxes are as long to write out, etc.