I have a feeling that this question is too easy, but I am having a hard time with it. I am building some very complex re's by combining sub-expressions using variable interpolation, which works fine. The problem is, certain backslash characters are being interpolated, too, in particular a dot match "\." is interpolated to ".", which isn't the same at all in a re. I would like to find a way to retain variable interpolation but turn off character interpolation, if that is possible.

A couple of extra-difficulty points:

The re's are values in a hash, which makes using concatenation not only messy, but impractical, too.

The depth of nesting of sub-expressions is variable, so that multiple slashes would be very difficult to maintain.

If the answer to all this is simple and obvious, I promise to eat several pages of the "Perl Cookbook".

OK, as requested, here is a contrived example I think illustrates the situation:

my $name = '(\w[\w-]*\w?)'; # any valid hostname segment my $nnam = "(($name\.)*$name)"; # one or more "name" segments my %domainnames = ( "$nname\.com" => 'a commercial domain', "$nname\.edu" => 'an educational institution', )
I just made this up, and it might not work as is, but I think it illustrates the point. The re does, indeed, match one or more legal domain name segments followed by the respective TLD. Unfortunately, instead of matching the dots, it matches any single character, because the "\." need by the re is interpolated by the string operator "" along with the variables $name and $nname. So, if only the interpolation of the characters could be prevented while allowing the interpolation of the variables, this would work, probably.

Thanks


In reply to variable interpolation sans character interpolation by vacant

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.