Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Replacing multiple spaces into one character?

by thunders (Priest)
on Oct 09, 2001 at 19:01 UTC ( [id://117756] : note . print w/replies, xml ) Need Help??


in reply to Replacing multiple spaces into one character?

1 while $str =~ s/[ ]+/_/;
will also work for this one, it's similar to the /g modifier except that it re-evaluates the entire string after every substitution. But this is for entertainment TIMTOWTDI value only cause something like this
1 while $str =~ s/[ ]+/ _ /;
will just keep running forever as it tries to replace the spaces it creates.