Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
What I want to do is go up to three keywords at a time (one word, two words and three word phrases). The one word is easy, I'll rip through the array and populate a $hash++ with it. But now moving on to two and three keyword phrases.
I was thinking about tossing in a regex in the split (assuming we can do that) to match 2 words and 3 words. Unfortunately my regex skills aren't up to par quite yet and not sure how to go about that.
The first problem I am having is it's breaking up on my apostraphes making the following 's' a new word I don't want that.
I would like to see some advice on how to go about doing this the way I am trying to before seeing other methods on how to do this. I know there are ways to produce shorter code, but this is probably easiest for me to understand right now.my $content = qq(Three blind mice. Three blind mice. See how they ru +n. See how they run. The butcher's wife came after them with a knif +e, three blind mice.); my @words = split(/\W/, $content); chomp(@words); foreach (@words) { print "$_\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Word density
by jdporter (Paladin) on Mar 19, 2006 at 19:41 UTC | |
|
Re: Word density
by ikegami (Patriarch) on Mar 19, 2006 at 19:00 UTC | |
by Anonymous Monk on Mar 19, 2006 at 19:20 UTC | |
by ikegami (Patriarch) on Mar 19, 2006 at 19:25 UTC | |
by Anonymous Monk on Mar 19, 2006 at 19:29 UTC | |
by sulfericacid (Deacon) on Mar 19, 2006 at 19:36 UTC | |
by ikegami (Patriarch) on Mar 21, 2006 at 01:26 UTC | |
|
Re: Word density
by blokhead (Monsignor) on Mar 19, 2006 at 19:00 UTC | |
|
Re: Word density
by GrandFather (Saint) on Mar 19, 2006 at 21:10 UTC | |
|
Re: Word density
by ambrus (Abbot) on Mar 19, 2006 at 20:22 UTC | |
|
Re: Word density
by sulfericacid (Deacon) on Mar 19, 2006 at 18:57 UTC | |
|
Re: Word density
by planetscape (Chancellor) on Mar 20, 2006 at 03:52 UTC | |
|
Re: Word density
by eric256 (Parson) on Mar 21, 2006 at 04:10 UTC |