Shared publicly  - 
 
Why isn't there a straight forward answer to trimming a string in PERL? regex speed tests comparing two regexs vs a single regex...i just want a simple trim function that I can count on being there, without defining one myself. CPAN is fine, but what is that module. trim in the core?
TRIM in Perl? by peacemaker1820 (Pilgrim). Log in; Create a new user; The Monastery Gates; Super Search; Seekers of Perl Wisdom; Meditations; PerlMonks Discussion; Obfuscation; Reviews; Cool Uses For ...
1
Lars Dɪᴇᴄᴋᴏᴡ's profile photoDave Horner's profile photoCurtis Poe's profile photoJohn Douglas Porter's profile photo
9 comments
 
.strip() in python. PERL, we get two regexs as defacto, with a single concise regex questioned as to speed. timtowtdi.
 
Adding trim to the language means defining a keyword and that conflicts with code that already contains e.g. a trim subroutine, IOW it's not backward-compatible and that goes against P5P's conservative stance. You really want perl5i, where extending the language becomes as simple as adding just another method, and trim is already included. <http://p3rl.org/perl5ifaq#How-do-I-strip-whitespace-off-a-string-> Using a module is always an option, see Sam Graham's comparison. <http://www.illusori.co.uk/perl/2010/03/05/advanced_benchmark_analysis_1.html>
 
Thank you Lars, I had not seen String::Strip or the perl5i trim!

I would prefer using a perl5i, but prefer the portability of something like String::Strip, but then you see two open bugs, one of which is looking for a maintainer/more test/modernization.
https://rt.cpan.org/Public/Dist/Display.html?Name=String-Strip

It surprises me the value of having something like strip() defined within the language... or even within the 3rd party module librarys (CPAN). Why String::Strip didn't exist until 2000, and today has two open bugs doesn't make sense to me. It is so common a task, and most people just bite the bullet and inline the double regex statements or define their own method to hide the double regex.

looks like .trim is coming in perl 6...so perl5i is portable in a sense....
http://groups.google.com/group/perl.perl6.internals/browse_thread/thread/5e9f3fadd849193c?pli=1

Thanks again Lars.
 
+Dave Horner .trim() is also built-in to Perl6. I wrote the original implementation in PASM, but I suspect it's been rewritten by now as my implementation was a couple of years ago.
 
Right, maybe you didn't see my full expanded comment:
looks like .trim is coming in perl 6...so perl5i is portable in a sense....
http://groups.google.com/group/perl.perl6.internals/browse_thread/thread/5e9f3fadd849193c?pli=1
portable, but forcing the developer to move to perl6/perl5i to get it. (which is best I guess)
CPAN module route seems like it would be an easy and portable way. But you feel silly to import a module just for strip...not to mention outstanding 64bit bug and no maintainer.

going to perl6 isn't a walk in the park conversion, and I'm not familiar with perl5i, but it looks like a nice alternative. Systems are out there with 5.x and they need to continue working. I wonder how perl5i does on all the platforms aix/sun/etc with older 5.x. perl5i and .trim() may be what I have been searching for.

Thanks for the note Curtis, I haven't tried a bit of PASM myself yet, maybe some day.
 
Being a Perl programmer has helped me get plenty of trim. What's your problem?
 
Yes, being a Perl programmer has caused many a developer to implement their choice of a trim implementation, each in their own code. Did I not expound the point enough?
 
+Dave Horner You're right, I didn't see your full comment. Now I'm curious to know if my code still survives. I'll have to check :)
 
my comment above was meant to be humorous. I'm sorry if I offended anyone.
Add a comment...