There are several advantages to templates (HTML::Template is my fave, and a popular choice), among which on emight include:
- easy to cannibalise existing HTML
- re-usable (bits that crop up in page after page can have their own, single, template)
- easy to change "skins"
- data hiding - pushes the formatting choices into their own space where you can forget about them
- easier to handle situations where you've got lots of different things that you might output in the same format
Having said that, for short and simple data output, I agree that the overhead in setting up the template (overhead in terms of that most important=to-optimise variable, developer time) sometimes makes one want to dump it straight into the code.
In this case (as in so many others) CGI.pm is often the way to go, as its built in functions make on-the-fly html generation in the code a good deal quicker and more readably integrated with the rest of the code. Your example wd become:
use CGI qw/:standard/;
print
header,
start_html,
"Today's variable is: ",
$myvar,
end_html;
+ n.b. that the more complex the html you are outputting, the more time and space the CGI functions become.
When dumping large quantities of info into html tables, I felt the need of
something like this, which you may also find useful.
§
George Sherston
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.