in reply to Re^3: Replace consecutive whitespaces with single whitespace
in thread Replace consecutive whitespaces with single whitespace
Besides which, the extra work is negligibleMaybe, maybe not. Whether it's negligible or not depends on the data at hand. If you have a long string with many single spaces it does matter as you avoid copying the string.
Copying the string on each single space is an inefficient algorithm.our $str = "x " x 1000; cmpthese -1, { single => sub {local $_ = $::str; s/\s+/ /g}, multiple => sub {local $_ = $::str; s/\s{2,}/ /g;} }; __END__ Rate single multiple single 1969/s -- -40% multiple 3287/s 67% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Replace consecutive whitespaces with single whitespace
by tilly (Archbishop) on Mar 27, 2009 at 13:20 UTC |