|
Prev: Setting permissions on remote directory using Net::SFTP
Next: Encoding problem: Rsquo to a with a hat
From: Leif Wessman on 25 Oct 2006 11:03 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 25 Oct 2006 11:31 "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 25 Oct 2006 11:42 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 25 Oct 2006 12:36 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 25 Oct 2006 12:41 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
|
Next
|
Last
Pages: 1 2 Prev: Setting permissions on remote directory using Net::SFTP Next: Encoding problem: Rsquo to a with a hat |