I'm sorry, were the two nodes showing the "obvious" solution not enough? Well, there are three now, so I hope that finally suffices. :)

There are lots of ways to follow a variable's contents by a \w character or ' or :: or brackets/braces. Numerous of them I find less ugly than the "obvious" "${x}_", especially when you include cases like "${h{$k}}{$s}". This is simply a personal preference, not even something I bother to recommend to others. But it is worth demonstrating one or more of the alternatives on occasion.

Long runs of expressions separated by commas have a lot of advantages over longs runs of concatenations. Those advantages are just some of the reasons why I use join in places where others might use concatenations or sprintf or here-docs or large strings full of interpolations (or maybe even a templating system). The code that implements PerlMonks does a lot of building of strings and over the years I've tried a lot of different styles but join is the one that has survived, faring significantly better than the alternatives in the face of having to maintain such code.

Concatenation has the wrong precedence for even trivial cases like $i+1 . ") $a[$i]\n". Coders are quite used to formatting long runs of comma-separated expressions nicely while the "obvious" way to format a long run of concatenations (over multiple lines of code) is not clear, IME. The dot is easy to lose sight of and also easy to confuse with a comma. Conversely, the comma's cannonical positioning without whitespace in front of it and either at the end of a line or with whitespace after it, makes it easy to recognize. Thankfully, Perl allows the last expression to also be followed by a comma (not true with concatenating). join ' ' is also often a better choice, preventing some common mistakes like print "There are", $x->count(), "items.".

Okay, I'm tired. I'm sure there are still some advantages that I've neglected to mention just comparing concatenation to join. And I'm going to go to bed rather than mention any of the problems with sprintf or here-docs etc.

- tye        


In reply to Re^3: *Join* with more than one EXPR by tye
in thread Join with more than one EXPR by sesemin

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.