I think the first example you give is quite nice.

I quite dislike your second example, however. I find it far too difficult to map between the too-many format specifiers spread (rather willy-nilly) over multiple lines and the unnumbered list of expressions below. If the format specifiers had numbers or names, then it would bother me less. I understand your point of disliking having the over-all format broken up.

I've run into enough cases quite a bit longer than your second example and just don't find that sprintf scales to such situations. It can make quite clear code for the small cases, but I dislike the risk of variables being interpretted directly into the format string (because I've seen it happen so often when sprintf is used) and especially don't like how it doesn't scale. So I quickly jump to the method that scales the best, and also produces quite readable code, IMHO.

- tye        


In reply to Re^3: Perl style: Arguing against three-argument join() (scale) by tye
in thread Perl style: Arguing against three-argument join() by martin

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.