jeanluca:

I can't think of any better way to do string concatenations than the ones you presented. But next time you ask a question like this, you might want to tell us which measure of "better" you want: Faster? Smaller? More maintainable? On many occasions, you'll find that each measure of better leads to a different answer, and you'll find people giving you answers based on which "better" the writer is assuming you mean. (I keep tending toward "faster" because of my nature, but with the sort of stuff I do, I should be leaning toward clarity and maintainability...

That said, I think the ones you presented are probably very good in all three measures. It's certainly clear and maintainable. I don't benchmark Perl programs, but it's such a common operation that I imagine the compiler does a pretty good job on speed and size as well. (There are more variations of "better" as well, but those are the only three I ever think about....)

--roboticus


In reply to Re: add text to a string by roboticus
in thread add text to a string by jeanluca

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.