sftriman wrote: > I use this series of regexp all over the place to clean up lines of > text: > > $x=~s/^\s+//g; > $x=~s/\s+$//g; > $x=~s/\s+/ /g; > > in that order, and note the final one replace \s+ with a single space. > > Basically, it's (1) remove all leading space, (2) remove all trailing > space, > and (3) replace all multi-space with a single space [which, at this > point, > should only occur on interior characters]. > > Is there a handy way to do this in one regexp? And, fast? I've been > using Devel::NYTProf to study code timing and see that some regexp, > especially mine, can be CPU expensive/intensive. > > Thanks! > David > >
tr/// is generally faster than s/// $text =~ tr{\t}{ }; $text =~ tr{\n}{ }; $text =~ tr{\r}{ }; $text =~ tr{\f}{ }; $text =~ tr{ }{ }s; -- Just my 0.00000002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/