How to concatenate variables in Perl

后端 未结 6 1127
面向向阳花
面向向阳花 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:06

    If you change your code from

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

    to

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

    or

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

    it will print

    $linenumber is:
    22
    

    What I find useful when wanting to print a variable name is to use single quotes so that the variables within will not be translated into their value making the code easier to read.

提交回复
热议问题