Michael Alipio wrote:

my $string = "This is a sentence";

Now, I want to join "is" and "a" by a dash.

Any idea how do i do that?

using regexp may not be want I want because the real string contains many
words, so I have to join several words without using too much regexp
substitutions.

This is the same question as before with different numbers. It would help if you
posted the real problem instead of making up other problems that were a bit like
it. Anyway, in the spirit of TIMTOWTDI, here is a different solution.

HTH,

Rob


use strict;;
use warnings;

my $string = "This is a sentence";

my $n = 0;
$string =~ s/\s+/++$n; $n == 2 ? '-' : ' '/ge;

print $string, "\n";

**OUTPUT**

This is-a sentence

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to