You should know that perl is a general purpose language. So you'll see many functions in perl that have nothing to do with creating web pages. But because perl excels at processing text, it excels at creating web pages.

In addition, you should know that using printf may not be the most efficient way of creating web pages. From the context of your question, it sounds like you are spitting out little pieces of HTML.

More advanced systems collect all of those little pieces of HTML, format and then print the page all at once (this is where sprintf can help). This has benefits when you start querying databases to build your page. If you start printing out HTML before all of your page processing completes, what happens when you run into a serious error further down the page? You can't pull back the parts of the page you've already printed.

In reply to Re: Why SprintF? by donarb
in thread Why SprintF? by JasonCgi

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.