Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by jeffa (Bishop)
on Nov 20, 2015 at 21:44 UTC ( #1148266=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1148266]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2019-05-23 05:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (142 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!