I am trying to search a file for a given word and return the whole line.
If i specifically define the word such as below, it works perfectly however I want to use a array of keywords that can be used for the regex how would I go about doing this?
The keywords used are from a text file stored as
Hello
Cat
Dog
They are called using the code:
$words = '/computer/textfile';
open(WORDS, $words);
@wordarray = <WORDS>;
This works:
while($line = <FILE>) {
if($line =~ /Hello/) {
print "$line\n";
}
}
This does not work:
while($line = <FILE>) {
if($line =~ @wordarray) {
print "$line\n";
}
}