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


in reply to How to include a string immediately after a variable in a double-quoted string

You can also use printf/sprintf to keep your data separated from the "presentation":

printf "The maximum number of %sevents on %s occurred %d times; it was + %d.\n", $type, $date, $maxtimes, $max, ;

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on Re: How to include a string immediately after a variable in a double-quoted string
  • Download Code

Replies are listed 'Best First'.
Re^2: How to include a string immediately after a variable in a double-quoted string
by stevieb (Abbot) on Nov 20, 2015 at 22:54 UTC

    I always forget about printf in Perl. In Python (3+), there's no interpolation, so I'd have to do print("Hello {}, how are you {}".format(name, today)).

    No matter what you want to print with variables, you have to do it this way (at least for a normal print statement), including all the parens and cruft.

    I've taken perl interpolation for granted me thinks ;)

Re^2: How to include a string immediately after a variable in a double-quoted string
by msh210 (Scribe) on Nov 22, 2015 at 04:57 UTC

    Thank you!

    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