Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks
I use the following to discard stopwords, which are saved in an array, from my process
my $word="of"; my @stopwords= ("a","the","of"); if (grep /$word/i, @stopwords) { print "Stopword $word discarded\n"; } else{ print "$word is not a stop word\n"; }
This works fine if my $word has only one word, it just matches everywhere. It becomes complicated if $word is made out of more words, as I don't want to consider $word a stopword according to the position of the match. What I need to do is to exactily control the grep match, which means:
the position of the match, where the stopword is found in $word, for example at the beginning or at the end of $word. With $word="of the blue" match is true, $word="the blue of" match is true, $word="out of blue" match is no true
No idea where to start. I ould be glad if someone could give me some hint to work on.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: grep match variable position
by Laurent_R (Canon) on May 16, 2016 at 13:28 UTC | |
|
Re: grep match variable position
by Marshall (Canon) on May 16, 2016 at 14:38 UTC | |
|
Re: grep match variable position
by AnomalousMonk (Archbishop) on May 16, 2016 at 14:53 UTC | |
|
Re: grep match variable position
by QuillMeantTen (Friar) on May 16, 2016 at 11:56 UTC | |
|
Re: grep match variable position
by hippo (Archbishop) on May 16, 2016 at 15:45 UTC | |
|
Re: grep match variable position
by jdporter (Paladin) on May 18, 2016 at 13:08 UTC | |
|
Re: grep match variable position
by Anonymous Monk on May 16, 2016 at 16:10 UTC |