It seems like every time a write a new CGI app, I take a different approach on how to get HTML to look reasonable inside my code. I can't seem to find the perfect way to do so. I'm sure some monks out there have some great ideas I haven't thought of yet.
For getting HTML to not look horrid in Perl, I've tried various things. The tag-generation code in CGI.pm is certainly OK, but that seems like it's best suited for simpler applications. The output is ugly, however I've written my own replacement to fix that. And autoescaping aside, I think print $q->table({border=>0,cellpadding=>0,cellspacing=>0,bgcolor=>"#ffffff"},$stuff) can get a little out of hand when compared to print qq[<table border=0 cellpadding=0 cellspacing=0 bgcolor=#ffffff>$stuff</table>] (OK, so maybe I hate writing out everything into an anonymous hash)
Then there's templating the HTML, which is a great way to separate it out of your Perl, except eventually the templating system must be its own programming language or else not all of your HTML stays away from the Perl. I usually need the templates to be simple so the HTML jockeys don't have to learn a scripting language.
Recently I've discovered Interpolation.pm, so I can do stuff like:
print qq|<a href="blah.cgi?search=$M{param("search")}">link</a>|;
# %M is tied to some mime encoding function
I'm still getting the hang of this, but it certainly doesn't solve all the nuisances of combining HTML with Perl. I'd like to know what the rest of the world does to cope with these issues ;)
Thanks!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|