Actually, I'd probably go with my own variant (see above), which happens to be faster than either of these.
Yours isn't the fastest for me, although I've added use warnings, use strict; and forced a scalar context unto the substitution:
#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); my $test_text = q|Wow, that was quick!<br/> Two points:<br/> 1) I only want space, not tabs or new lines - so shouldn't the \s be + replaced with " "? <br/> 2) Is there a difference between inkgmi's and GrandFather's entry? <b +r/> PS I thought executed regexs are experimental (so says the man page) - + is there a problem with them?<br/> |;
cmpthese(-3, { GrandFather => sub { local $_ = $test_text; scalar s/ ( +)/" " . (" " x length ($1))/ge }, ikegami => sub { local $_ = $test_text; scalar s/(?<= )( +)/' ' x length($1)/eg }, Smylers => sub { local $_ = $test_text; scalar s/(?<= )( )/ /g }, }); __END__ Rate ikegami Smylers GrandFather ikegami 22180/s -- -25% -31% Smylers 29772/s 34% -- -8% GrandFather 32268/s 45% 8% --
In reply to Re^6: Converting multiple spaces to nbsp
by ikegami
in thread Converting multiple spaces to nbsp
by eastcoastcoder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |