On Fri, Feb 19, 2010 at 3:23 PM, John W. Krahn <jwkr...@shaw.ca> wrote: > Sergey Matveev wrote: >> >> Greetings, >> >> On Fri, Feb 19, 2010 at 03:54:27PM -0500, Erik Lewis wrote: >> >>> I have to changes all the spaces in a string to +'s. Is there an >>> easy way to do this. The length of the string and the number of >>> spaces will always be changing. >> >> $string =~ s/ /\+/g; >> >> That is all. All spaces will be replaced. > > You don't have to escape a plus sign in a quoted string: > > $string =~ s/ /+/g; > > Or for a more efficient way: > > $string =~ tr/ /+/;
For example: $ echo "foo bar zoo" | perl -pne '$_ =~ s/ /+/g' foo+bar++zoo $ echo "foo bar zoo" | perl -pne '$_ =~ y/ /+/' foo+bar++zoo Regards, - Robert -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/