SPUG: multiple spaces in string

apv apv at sedition.com
Wed Feb 8 13:42:18 PST 2006

On Wednesday, February 8, 2006, at 11:31  AM, jerry gay wrote:
> using the transliteration operator
>   $string =~ tr/ //s;
> may be more accurate than a regular expression
>   $string =~ s/\s+//g;
> as it won't replace tabs, or combinations of spaces and tabs.
> generally, it's also faster, as it does not perform backtracking.

That's right and even s/\s+/ /g can be improved b/c as is it is 
every " " with a " " too which is pointless. This would be closer to the
literal intent:
   s/  */ /g;
  # or even
  s/(?<= ) *//g;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 584 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/spug-list/attachments/20060208/fb572cf1/attachment.bin

More information about the spug-list mailing list