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:
- print "The maximum number of $type" . "events on $date occurred $maxtimes times; it was $max.\n";
- 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?