$NetPattern = qr{mbist[\w+\d+\/]*\[\d+\]}x; if ($NetName =~ $NetPattern) {# Do fantastical things...}
$NetPattern = 'mbist[\w+\d+\/]*\[\d+\]'; if ($NetName =~ qr/$NetPattern/x) {# Do fantastical things...}
The "" style quotes interpolated your slashes away.
The qr is also most useful (in my opinion) for precompiling regular expressions, so I would choose the first solution, particularly if you have a lot of matches to do on that single regular expression. It's also nice for being able to tell that $NetPattern is of type Regexp. So, I guess there's also this third choice...
$NetPattern = 'mbist[\w+\d+\/]*\[\d+\]'; if ($NetName =~ m/$NetPattern/x) {# Do fantastical things...}
-Paul
In reply to Re: Comparing two variables when one variable includes a regexp...
by jettero
in thread Comparing two variables when one variable includes a regexp...
by fiddler42
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |