Sharan Basappa wrote:
Hi,
Hello,
I have string that has one or more spaces. I would like to replace them with a single space.
$ perl -le' my $temp = "0 1 2 3 4"; print $temp; $temp =~ tr/ //s; print $temp; ' 0 1 2 3 4 0 1 2 3 4
The simple code below replaces the spaces fine, but does not substitute with a space. $temp = "0 1 2 3 4"; <-> version 1 $temp =~ s/\s+/\s/g; $temp = "0 1 2 3 4"; <-> version 2 $temp =~ s/\s+/s/g; They both end up actually substituting spaces with string s
That is because you use "s" as the replacement string. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/