Variable Interpolation
Languages differ on whether and how to interpret string literals as either 'raw' or 'variable interpolated'. Variable interpolation is the process of evaluating an expression containing one or more variables, and returning output where the variables are replaced with their corresponding values in memory. In sh-compatible Unix shells, quotation-delimited (") strings are interpolated, while apostrophe-delimited (') strings are not.
For example, the following Perl code:
$name = "Nancy"; $greeting = "Hello World"; print "$name said $greeting to the crowd of people.";produces the output:
Nancy said Hello World to the crowd of people.The sigil character ($) is interpreted to indicate variable interpolation.
Similarly, the printf
function produces the same output using notation such as:
The metacharacters (%s) indicate variable interpolation.
This is contrasted with "raw" strings:
print '$name said $greeting to the crowd of people.';which produce output like:
$name said $greeting to the crowd of people.Here the $ characters are not sigils, and are not interpreted to have any meaning other than plain text.
Read more about this topic: String Literal
Famous quotes containing the word variable:
“There is not so variable a thing in nature as a ladys head-dress.”
—Joseph Addison (16721719)