I have an array like this
my @stopWords = ("and","this",....)
My text is in this variable
my $wholeText = "....and so this is...."
I want to match every occurrence of every element of my stopWords array in the scalar wholeText and replace it with spaces.
One way of doing this is as follows :
foreach my $stopW (@stopWords)
{
$wholeText =~ s/$stopW/ /;
}
This works and replaces every occurrence of all the stop words. I was just wondering, if there is a shorter way of doing it.
Like this:
$wholeText =~ s/@stopWords/ /;
The above does not seem to work though.
1 Answer