Now perhaps one could argue that "faster" should be replaced with something a bit more encompassing (better, 'the right choice', etc), but in the end what really is the difference between s|\.|/|g and tr|\.|/|?
What if the question had been:
Would it still be considered premature optimization to suggest that substr is the correct answer?
In both questions there is a solution that uses a slower general tool (regex, split) and one with a faster specialized tool (tr///, substr). If you aren't going to use the specialized tools in these cases, when are you *ever* going to use them?
Oh, and I posted some benchmarks a while back showing tr/// running about 15 times faster that s/// for a particular case...
Update: virtualsue has brought to my attention that her "premature optimization" statement was about running benchmarks for small insignificant parts of a program. She wasn't advocating s/// over tr/// in this case, simply stating that benchmarking the two was a poor use of human cycles. To that I wholehartedly agree... I seem to have read the node slightly out of context, and get a little touchy when I see people using elephant guns (s///) when a well designed flyswatter (tr///) would do.
-Blake
In reply to Re: Re: Re: tr/// vs s/// for single character
by blakem
in thread tr/// vs s/// for single character
by Flame
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |