[LA.pm] C-style Perl vs. regex

Benjamin J. Tilly ben_tilly at operamail.com
Wed Feb 8 14:22:53 PST 2006


"Peter Benjamin" <pete at peterbenjamin.com> wrote:
[...]
> One optimization to use in your perl code is to get rid of
> join for concatenation.
> 
> >        my $zone = join "", $domain, ".zone";
> >        my $hosts = join "", " mail.", $domain, " www.", $domain;
> 
> Best is:
> 
> my $zone = "$domain.zone";
> 
> which is fastest and more readable.

Benchmarks, please.

I'll bet that you have a <b>very</b> hard time demonstrating a noticable saving.

> Do not use the concat operator of period, '.', as according
> to Larry, in chapters on perl optimization I have read,
> that period operator is slow.  The only time I use it is
> when I have to include an array or hash in a concatenation
> and the value is not first available in a temporary variable.
> For example:

Which chapters, where?  It is true that building up a long string using:

  $foo = $foo . "new stuff";

is slow - that is why .= exists.  But . itself is not to be avoided.

Remember that there are a lot of people who talk about optimization out there, and most of them spout crap.  When in doubt, benchmark.

Incidentally IIRC, interpolation is converted behind the scenes into concatenation.

Cheers,
Ben


More information about the Losangeles-pm mailing list