in reply to Re: Re: remove both leading and trailing spaces
in thread remove both leading and trailing spaces
#!/usr/bin/perl -w use strict; use Benchmark; my $val=" Smart Way "; timethese(1000000, { regex1 => sub { my $tmp = $val; $tmp =~ s/^\s*(.*?)\s*$/$1/g; }, regex2 => sub { my $tmp = $val; $val = join (" ",split " ",$val); }, regex3 => sub { my $tmp = $val; $tmp =~ s/^\s+//; $tmp =~ s/\s+$//; } });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: remove both leading and trailing spaces
by the_0ne (Pilgrim) on Sep 26, 2003 at 20:46 UTC |