Kind, Gentle Folk,

Okay, I am making a rookie mistake, but I can't figure out how to work around it. I am employing the "use Getopt::Long;" module to process command-line arguments. One of the arguments is a string, and it can include regular expressions. Here is a simple example:-

$NetPattern = "mbist[\w+\d+\/]*\[\d+\]";

But when I try to compare that pattern to another variable like so...

if ($NetName =~ qr/$NetPattern/x) {# Do fantastical things...}

...and $NetName is "top_level/mbist_wrapper_pix2d[22]" the compare fails. If a user enters a command-line regular expression that gets pushed into a variable, what is the most reliable way to use that variable to compare it against another variable that is a string?

Thanks,

Fiddler42


In reply to Comparing two variables when one variable includes a regexp... by fiddler42

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.