我一直在运行许多Perl代码,这些代码以这种方式分解了很长的字符串:

my $string = "Hi, I am a very long and chatty string that just won't";
$string .= " quit.  I'm going to keep going, and going, and going,";
$string .= " kind of like the Energizer bunny.  What are you going to";
$string .= " do about it?";

从我使用Java的背景出发,构建这样的字符串将是性能上的不行。 Perl也是如此吗?在搜索中,我读到在字符串数组上使用join是连接字符串的最快方法,但是当您只想分解字符串以提高可读性时该怎么办?最好写:
my $string = "Hi, I am a very long and chatty string that just won't" .
    " quit.  I'm going to keep going, and going, and going," .
    " kind of like the Energizer bunny.  What are you going to" .
    " do about it?";

还是我使用join,或者应该怎么做?

最佳答案

Camel book, p 598:

关于Perl字符串的性能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3104493/

10-12 06:23