How to concatenate variables in Perl

后端 未结 6 1129
面向向阳花
面向向阳花 2020-12-18 01:37

Is there a different way to concatenate variables in Perl?

I accidentally wrote the following line of code:

print \"$linenumber is: \\n\" . $linenumb         


        
6条回答
  •  一生所求
    2020-12-18 02:08

    In Perl any string that is built with double quotes will be interpolated, so any variable will be replaced by its value. Like many other languages if you need to print a $, you will have to escape it.

    print "\$linenumber is:\n$linenumber";
    

    OR

    print "\$linenumber is:\n" . $linenumber;
    

    OR

    printf "\$linenumber is:\n%s", $linenumber;
    

    Scalar Interpolation

提交回复
热议问题