go ahead... be a heretic | |
PerlMonks |
Re: How to trim a line from leading and trailing blanks without using regex or non-standard modulesby kcott (Archbishop) |
on Aug 14, 2020 at 09:35 UTC ( [id://11120714]=note: print w/replies, xml ) | Need Help?? |
G'day likbez, I will usually reach for one of Perl's string handling functions (e.g. index, rindex, substr, and so on) in preference to a regex when that is appropriate; however, in this case, I would say that the regex makes for much cleaner code. You could implement a trim() function using the guts of this code (which uses neither a regex nor any modules, standard or otherwise):
If your question was genuinely serious, please Benchmark a trim() function using something like I've provided against another trim() function using a regex. You could obviously do the same for ltrim() and rtrim() functions. [As others have either asked or alluded to, please explain phrases such as "definitely an overkill", "important special case" and "abuse of regex". Unfortunately, use of such language makes your post come across as some sort of trollish rant — I'm not saying that was your intent, just how it presents itself.] — Ken
In Section
Seekers of Perl Wisdom
|
|