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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.