String interpolation: Difference between revisions

Content deleted Content added
m Switched to “repeat”
Make the main example valid code
Line 3:
 
String interpolation is an alternative to building string via [[concatenation]], which requires repeat quoting and unquoting;<ref>{{Cite web|url=http://perlmeme.org/howtos/using_perl/interpolation.html|title = Interpolation in Perl |quote="This is much tidier than repeat uses of the '.' concatenation operator."}}</ref> or substituting into a [[printf format string]], where the variable is far from where it is used. Compare:
<syntaxhighlight lang="pythonruby">
apples = 4
print(puts "I have $#{apples} apples.") # string interpolation
print(puts "I have " + String(apples) + " apples.") # string concatenation
print(puts "I have %sd apples.", % apples) # format string
</syntaxhighlight>