How to concatenate variables in Perl

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

    I like .= operator method:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    my $text .= "... contents ..."; # Append contents to the end of variable $text.
    $text .= $text; # Append variable $text contents to variable $text contents.
    print $text; # Prints "... contents ...... contents ..."
    

提交回复
热议问题