Consider:
print " $foo", "AAAAAAAA", $foo, "BBBBBBBB";
Let's say I want to use this code with a print <<EOF;
:
print <<EOF; $fooAAAAAAAA$fooBBBBBBBB"; EOF
That won't work, because Perl thinks I have a variable called $fooAAAAAAAA
. How can I easily use print <<
with such lines when I have a long test to print?
Using string interpolation, we can use objects and expressions as a part of the string interpolation operation. C# string interpolation is a method of concatenating, formatting and manipulating strings. This feature was introduced in C# 6.
Interpolation in Perl refers to the process where the respective values replace the variable names. It is commonly used inside double-quoted strings.
The variables are shown ordered by the "distance" between the subsystem which reported the error and the Perl process...$@ is set if the string to be eval-ed did not compile (this may happen if open or close were imported with bad prototypes), or if Perl code executed during evaluation die()d.
In general, the string concatenation in Perl is very simple by using the string operator such as dot operator (.) To perform the concatenation of two operands which are declared as variables which means joining the two variables containing string to one single string using this concatenation string dot operator (.)
Use ${foo}
:
print <<EOF; ${foo}AAAAAAAA${foo}BBBBBBBB"; EOF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With