There are several advantages to templates (HTML::Template is my fave, and a popular choice), among which on emight include: 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

In reply to Re: OUTPUT: inline or template_based? by George_Sherston
in thread OUTPUT: inline or template_based? by CodeHound

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.