in reply to Comparing two variables when one variable includes a regexp...
$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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing two variables when one variable includes a regexp...
by Narveson (Chaplain) on May 01, 2008 at 18:25 UTC | |
by jettero (Monsignor) on May 01, 2008 at 19:24 UTC |