Michael Alipio wrote:
> Hi,

Hello,

> Suppose I have:
> 
> my $sentence = 'the quick brown fox jumps over the lazy dog."
> 
> Now I want it to become:
> 
> 'the quick brown:fox:jumps:over:the lazy dog."

One way to do it:

$ perl -le'
my $sentence = "the quick brown fox jumps over the lazy dog.";
$sentence =~ s/ +(?=.* +[^ ]+ +)/ ++$x > 2 ? ":" : " " /eg;
print $sentence;
'
the quick brown:fox:jumps:over:the lazy dog.



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/


Reply via email to