Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Replacing multiple spaces into one character?

by chromatic (Archbishop)
on Oct 09, 2001 at 07:10 UTC ( [id://117627] : note . print w/replies, xml ) Need Help??


in reply to Replacing multiple spaces into one character?

tr/ /_/s;, as /s is for squash multiple.

Doing it in one line while removing leading whitespace is trickier. There are several potentially nasty regular expressions. Just say no.

Update: Squashing several expressions onto one line technically counts, but it wasn't what I meant, smart guy!

Replies are listed 'Best First'.
Re: Re: Replacing multiple spaces into one character?
by tachyon (Chancellor) on Oct 09, 2001 at 07:24 UTC
    $str = ' say as simple as a b c :-) '; $str =~ s/^\s+|\s+$//g, $str =~ tr/ /_/s, print $str;