http://www.perlmonks.org?node_id=1148262

msh210 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Monks,

I have a bunch of scalar variables to include in a string. In order to avoid a bunch of ugly concatenation dots, I include them all in a double-quoted string. So far, so good. But one of the variables is to be followed, within the string, by some (non-variable alphanumeric) text. Obviously, I can't just concatenate them within the double-quoted string. Two options I can think of are:

  1. print "The maximum number of $type" . "events on $date occurred $maxtimes times; it was $max.\n";
  2. print "The maximum number of $type$\events on $date occurred $maxtimes times; it was $max.\n";   if $\ is undefined

But I don't much like either of those. The first is a bit ugly/inelegant to my mind: I prefer one long double-quoted string. The second is dependent on a variable that may change in a later revision of the script; plus, it's distasteful to me because there's nothing tying $\ to this string semantically.

Is there a more elegant way of doing this? Or is my option 1 (or 2?) considered elegant enough?

print map chr($w+=$_),74,43,-2,1,-84,65,13,1,5,-12,-3,13,-82,48,21,13,-6,-76,78,-9,18,-21,7,-4,-57,-34#stackoverflow.com/q/10858682