From: Leif Wessman on

Hi all!

How can I remove all words that have a length that is 3 or less?

"a lot of words in this text";

should become

"words this text"

Is it possible?

Leif

From: yankeeinexile on
"Leif Wessman" <leifwessman(a)hotmail.com> writes:

> Hi all!
>
> How can I remove all words that have a length that is 3 or less?
>
> "a lot of words in this text";
>
> should become
>
> "words this text"
>
> Is it possible?
>
> Leif
>

Here is your hint.
grep { length > 3 } @words;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lawrence Statton - lawrenabae(a)abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
sort them into the correct order.
From: Paul Lalli on
Leif Wessman wrote:
> How can I remove all words that have a length that is 3 or less?
>
> "a lot of words in this text";
>
> should become
>
> "words this text"
>
> Is it possible?

Yes, it's possible.

There are two approaches which jump out at me. You could use a
join/grep/split combination. Or you could use a regexp solution being
sure to include word boundaries.

What have you tried so far? How did it not work as you expected?

Paul Lalli

From: Mirco Wahab on
Thus spoke Leif Wessman (on 2006-10-25 17:03):

> How can I remove all words that have a length that is 3 or less?
> "a lot of words in this text";
> should become
> "words this text"
> Is it possible?

Hi Leif,

this is something Perl was invented for ;-)
I'll try to give a easy example and you'll
try to explain it line by line in your reply, ok?

use strict;
use warnings;

my $shortlen = 3;
my $fulltext = 'a lot of words in this text';
my $no_shorts = $fulltext;

$no_shorts =~ s/ \b \w{1,$shortlen} \b \s+//gmx;

print $fulltext, "\n";
print $no_shorts, "\n";



Regards,

Mirxo
From: Ted Zlatanov on
On 25 Oct 2006, yankeeinexile(a)gmail.com wrote:

> "Leif Wessman" <leifwessman(a)hotmail.com> writes:
>
>> Hi all!
>>
>> How can I remove all words that have a length that is 3 or less?
>>
>> "a lot of words in this text";
>>
>> should become
>>
>> "words this text"
>>
>> Is it possible?
>>
>> Leif
>>
>
> Here is your hint.
> grep { length > 3 } @words;

That's not a good hint.

Ted