[LA.pm] C-style Perl vs. regex
Peter Benjamin
pete at peterbenjamin.com
Wed Feb 8 09:46:36 PST 2006
At 08:35 AM 2/8/2006, Robin Rowe wrote:
>code). Instead of C-style it could have been implemented using tr, but I
There is nothing needing tr. tr is single letter substitution.
tr only got mentioned due to the first example of swapping x and y,
which are single letters.
Your code is fine using <<ZZZ to print as newlines are present.
>Please let me know how this code could be improved.
It can't be improved. If it works, it is not broken.
It could be speeded up, but why spend the effort on something
that is rarely run?
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.
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:
print "debug echo \$thisvalue[$nv]='" . $thisvalue[$nv] . "'<br>\n";
More information about the Losangeles-pm
mailing list