in reply to Re: Replace multiple strings in a string
in thread Replace multiple strings in a string
"faster" in this sort of context, even if true, is altogether irrelevant as any difference would be completely swamped by the time taken for the body of the loop. However the difference between:
for (;$i<$#Search+1;$i++) {
(which implies a continuation of a previous loop because of the missing $i initialisation btw) and
for my $i (0 .. $#Search) {
which is clear and succinct is absolutely compelling. Note in particular (you may have missed it because of the lack of white space) the hoop the C style for loop goes through to get the range correct? In the Perl style loop there are no hoops so the interpretation by the code author, the code maintainer and the Perl interpreter all align perfectly so the chance of the iteration range being wrong is pretty close to 0.
Clarity and thus maintainability is the key reason for preferring the Perl style loop almost always.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Replace multiple strings in a string
by Laurent_R (Canon) on May 08, 2014 at 11:36 UTC |