I'm trying to read regular expressions from a parameter file. This works as long as I specify the outer delimiters around the variable in the code. I include the delimiters in the variable, otherwise I have no way of allowing users to generate expressions that use external modifiers like:
/coWs/i
The parameter file (following) uses the first character to specify what operation (search or exception) the user wants to perform. The regexp runs from column 2 to the end of the line. What I want to do is use delimiters and modifiers included in the parameter file:
+/six/i -/were/
This works when delimiters are not included in the parameter file, but is very limited and flakey.
+[Ss][Ii][Xx]
Here is some of the code:
# Process Global Exceptions first foreach $except (@$glob_except) { $cexcept = substr($except, 1); $targf{$tkey} = "1:0" if ($tkey =~ /$cexcept/); # EXPANDS VARIABL +E HERE ### I would like the delimeters to be contained in the variable: ...( +$tkey =~ $cexcept); } elsif ($ttype eq '+') { if ($tkey =~ /$ttext/) { ; # EXPANDS VARIABLE HERE $targf{$tkey} = "3:$err_rtn"; $found = 1; } } elsif ($ttype eq '-' && substr($targf{$tkey},0,1) == 3) { if ($tkey =~ /$ttext/) {; # EXPANDS VARIABLE HERE $targf{$tkey} = "2:0"; $found = 0; } } else { ### ETCETERA ### THIS IS HOW THE HASH CONTAINING THE MATCH STRING IS LOADED elsif ($line_header eq '!') { ## Optional # Spec a global exception that affects all lines # interpolation takes place. unless ($trans_state == 2) {die "ERR: Global exception out of sequence";} push (@$glob_except, $line); # <= LOADING THE VARIABLE FROM + FILE # Trans state stays at 2 until set to 3 in subsequent logic

In reply to How do pack a regular expression in a variable? by pppaulll

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.