Michael Alipio wrote:
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."
That is, to replace the spaces between brown-fox, fox-jumps, jumps-over,
over-the, with ":".
Should I split the sentence and put each in an array then iterate over the
array? What do you think will be the quickest way to do this?
Your title says one thing and your example says another. You have replaced all
spaces with a colon except between the first three and the last three words.
What is it you actually want? The code below may help: it strips leading and
trailing whitespace and replaces the space between the third through the seventh
words with a single colon; all other whitespace is replaced with a single space.
If you need anything different from this then please come back to us.
HTH,
Rob
use strict;
use warnings;
my $sentence = 'the quick brown fox jumps over the lazy dog.';
my @words = split ' ', $sentence;
my @centre = splice @words, 2, 5;
splice @words, 2, 0, join ':', @centre;
$sentence = "@words\n";
print $sentence, "\n";
**OUTPUT**
the quick brown:fox:jumps:over:the lazy dog.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/