Problems? Is your data what you think it is? | |
PerlMonks |
Re^8: "advanced" Perl functions and maintainabilityby itub (Priest) |
on Dec 13, 2004 at 16:37 UTC ( [id://414444]=note: print w/replies, xml ) | Need Help?? |
Even without using study, the speed advantage of index is almost lost when the match is at the end of a long string.
Rate regex index regex 97087/s -- -2% index 98619/s 2% -- most Perl hackers still pull out m//... Ok, I agree that index is faster in some cases. However, I think there are good reasons for the behavior of most Perl hackers:
I realize that some of this reasons (particularly the last one) agree with your argument for using for and push instead of map. I just wasn't sure that your assertion regarding index was correct, as my benchmarks had shown the opposite in the past. Now I see that it depends on the situation. Regarding the readability of map vs for, I would say that a distinct advantage of map is that it documents the purpose of the loop right at the top (when used properly). As soon as you see the map keyword you'll know that you are building a list and you'll know where it is being stored; with for, you have to wait until you see the push to see the true purpose of the loop. Which approach is better depends on the intention of the coder, and I agree that the size of the block may be a factor to consider. The problem is that the exact line between map and for is blurry, partly a matter of style and personal preference.
In Section
Meditations
|
|