if ($i =~ m/@array2/) { print "$i is in array2 - skipping\n";
That regular expression is m/foo bar quux/ and english for that is "array2 is in $i - skipping\n". It won't work because you are looking for the string "foo bar quux".
my $regex = "("; foreach (@array2) { $regex .= $_ . "|"; } $regex .= ")";
$regex now contains the string "(foo|bar|quux|)" which says to match EITHER "foo" OR "bar" OR "quux" OR "", and EVERY string will match "".
You need something like:
my $regex = "("; $regex .= join "|", @array2; $regex .= ")";
In reply to Re: regex with arrays and variables
by jwkrahn
in thread regex with arrays and variables
by xorl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |