Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I separate Perl variables from text in interpolated strings?

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?

like image 794
Julien Avatar asked Feb 03 '09 06:02

Julien


People also ask

Can we use expressions inside string interpolation?

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.

Does Perl allow variable interpolation?

Interpolation in Perl refers to the process where the respective values replace the variable names. It is commonly used inside double-quoted strings.

What does $@ meaning in Perl?

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.

How do I concatenate in Perl?

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 (.)


1 Answers

Use ${foo}:

print <<EOF;     ${foo}AAAAAAAA${foo}BBBBBBBB"; EOF 
like image 123
Martin Carpenter Avatar answered Nov 06 '22 04:11

Martin Carpenter