in reply to trimming space from both sides of a string
Updated. Fixed based on the error GrandFather was kind enough to point out.
This reminds me of a discussion of the very thing from one of the newsgroups. It was almost certainly comp.lang.perl.misc in which it took place, about a decade ago. It included silly benchmarks. Yes, we're talking premature optimization of a simple line or two not likely to be a critical point and all that. I seem to remember that s/^\s.*//; s/\s.*$//; s/^\s*//; s/\s*$//; both did very well in the benchmarks and was accepted pretty well as clear over clever. It beat out things involving extra interpolations, substr, etc.
Now, let me leverage Google Groups to refresh my memory and see if the above conclusion I recall was right. It might be interesting (although still somewhat silly) to see how the benchmarks compare on more modern perls compared to what we had then.
Here's one such: NEED: Fast, Fast string trim(). Here's another: Removing spaces in a string. It turns out there are several such threads in the newsgroup on this topic between 1996 and 2002, with some later than that. Moreover, more than one went so far as to include benchmarks.
This obviously doesn't prove the strange ones ever made it into larger projects, but given there were proponents for strange constructions there's a chance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: trimming space from both sides of a string
by GrandFather (Saint) on Oct 16, 2010 at 06:20 UTC | |
by mr_mischief (Monsignor) on Oct 16, 2010 at 16:04 UTC | |
by jwkrahn (Abbot) on Oct 16, 2010 at 19:31 UTC |