What they say in Java is just as true in Perl

use Benchmark::Dumb 'cmpthese';

( $bar, $quux ) = qw( bar quux );

cmpthese( 0.0002, {
  conc => q{
    my $str = "xxx ";
    (((( $str .= "foo" ).= $::bar ).= "baz" ).= $::quux ).= "qux";
  intp => q{
    my $str = "xxx ";
    $str .= "foo${::bar}baz${::quux}qux";
} );

I don’t recall ever seeing anyone mention this.

(It is, of course, obvious, and it is, of course, irrelevant in most contexts, especially as it is, of course, not a huge difference. Perl structurally tends to make it less likely to make this mistake in an accidentally quadratic way compared to how Java tends to be written, anyway. And anyhow, instead of micro-optimising Perl code this way, we all rewrite it – of course – in C… right?)

Leave a comment

About Aristotle

user-pic Waxing philosophical