Is there a different way to concatenate variables in Perl?
I accidentally wrote the following line of code:
print "$linenumber is: \n" . $linenumber;
And that resulted in output like:
22 is:
22
I was expecting:
$linenumber is:
22
So then I wondered. It must be interpreting the $linenumber in the double quotes as a reference to the variable (how cool!).
What are the caveats to using this method and how does this work?
Variable interpolation occurs when you use double quotes. So, special characters need to be escaped. In this case, you need to escape the
$:It can be rewritten as:
To avoid string interpolation, use single quotes: