blahblahblah has asked for the wisdom of the Perl Monks concerning the following question:
Recently I've been alerted to the fact that there are possibly much faster ways to do this. It seems japhy has written much about this, including a good overview with benchmarks at Regexes are slow (or, why I advocate String::Index). That post is pretty old, so I tried some of his benchmarks on perl 5.10. I found similar results. However, I noticed that his benchmarks all have long data, but my situation is that the data length will be varied, and often will be very short. Here are my results, once with long data and once short:How do I strip blank space from the beginning/end of a string? (contributed by brian d foy) A substitution can do this for you. For a single line, you want to replace all the leading or trailing whitespace with nothing. You can do that with a pair of substitutions. s/^\s+//; s/\s+$//;
Update: As Ikegami pointed out, my benchmark had little to do with my stated question. See reply below for a new attempt at this.
You might call this micro-optimization, but my users really would notice a couple-second difference as these scripts are running in a web app. I'm wondering if I can zero in on a particular string length where the "last" method degrades and the "segexer" becomes better. I don't have a lot of benchmarking experience, so even if I find that spot I'm not sure I'll trust my data or my methods. Just looking for advice from those who may have pondered this before or have insight that they can lend.
Update:crossed out non-applicable benchmark. See reply below for my latest attempt.