Writing a program where I read in a list of words/symbols from one file and search for each one in another body of text.
So it's something like:
while(<FILE>){
$findword = $_;
for (@text){
if ($_=~ /$find/){
push(@found, $_);
}
}
}
However, I run into trouble once parentheses show up. It gives me this error:
Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE
I realize it's because Perl thinks the (
is part of the regex, but how do I deal with this and make the (
searchable?
You could use \Q
and \E
:
if ($_ =~ /\Q$find\E/){
Or just use index
if you're just looking for a literal match:
if(index($_, $find) >= 0) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With