Your example is how it's done in HTML::Mason, although the syntax would be slightly different. For one thing, you don't need the printf at all, since you're just printing a string. So you can do any of these:
<% $some_string %>
% print $some_string;
Like others here, I prefer frameworks these days. Mixing code with layout just doesn't scale well at all. Mason is better than PHP because it's Perl, but things still get ugly easily for some of the same reasons they do in PHP. Currently I'm using Dancer with Dancer::Template::Mason as my templating system, and liking that quite a bit. My templates are Mason, so they can use Perl code for things like loops, rather than requiring me to learn some new templating system's loop syntax. But since all my actual code that processes the data (Controller and Model, in MVC terms) is separate, the template files are still very clean.
Available for small or large Perl jobs; see my home node.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||