I have a list of substrings that I need to map in a list of URL strings. Substrings have special characters, such as '|', '*', '-', '+', etc. If the URL strings contain this substring, I need to perform some operation. But now let's just say that I type “TRUE” in the console.
I did this on the first reading from the list of substrings and put it in a hash. Then I tried to perform a simple Regexp match of the entire list for each URL until a match was found. The code looks something like this.
open my $ADS, '<', $ad_file or die "can't open $ad_file"; while(<$ADS>) { chomp; $ads_list_hash{$lines} = $_; $lines ++; } close $ADS; open my $IN, '<', $inputfile or die "can't open $inputfile"; my $first_line = <$IN>; while(<$IN>) { chomp; my @hhfile = split /,/; for my $count (0 .. $lines) { if($hhfile[9] =~ /$ads_list_hash{$count}/) { print "$hhfile[9]\t$ads_list_hash{$count}\n"; print "TRUE !\n"; last; } } } close $IN;
The problem is that the substrings contain many special characters that cause errors in the match $hhfile[9] =~ /$ads_list_hash{$count}/ . A few examples:
+adverts/ .to/ad.php| /addyn|*|adtech;
I get an error in lines like these, which basically say: "Quantifier does not follow anything in regexp." Do I need to change something in the regular expression matching syntax to avoid this?
source share